Skip to content

Commit 6ea115c

Browse files
committed
Merge pull request #720 from elasticsearch/feature/copyto
added copy to field mapping support for appropriate types
2 parents bedc040 + 82157a3 commit 6ea115c

12 files changed

+102
-49
lines changed

Diff for: .editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ indent_size = 4
1919
[*.markdown]
2020
indent_style = spaces
2121
indent_size = 2
22+
23+
[*.json]
24+
indent_style = spaces
25+
indent_size = 2

Diff for: src/Nest/Domain/Mapping/Descriptors/BinaryMappingDescriptor.cs

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Linq.Expressions;
34
using Nest.Resolvers;
45

@@ -25,5 +26,16 @@ public BinaryMappingDescriptor<T> IndexName(string indexName)
2526
return this;
2627
}
2728

29+
public BinaryMappingDescriptor<T> CopyTo(params string[] fields)
30+
{
31+
this._Mapping.CopyTo = fields.Select(f => (PropertyPathMarker)f);
32+
return this;
33+
}
34+
35+
public BinaryMappingDescriptor<T> CopyTo(params Expression<Func<T, object>>[] objectPaths)
36+
{
37+
this._Mapping.CopyTo = objectPaths.Select(e => (PropertyPathMarker)e);
38+
return this;
39+
}
2840
}
2941
}

Diff for: src/Nest/Domain/Mapping/Descriptors/BooleanMappingDescriptor.cs

+11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Linq.Expressions;
34
using Nest.Resolvers;
45

@@ -52,6 +53,16 @@ public BooleanMappingDescriptor<T> IncludeInAll(bool includeInAll = true)
5253
return this;
5354
}
5455

56+
public BooleanMappingDescriptor<T> CopyTo(params string[] fields)
57+
{
58+
this._Mapping.CopyTo = fields.Select(f => (PropertyPathMarker)f);
59+
return this;
60+
}
5561

62+
public BooleanMappingDescriptor<T> CopyTo(params Expression<Func<T, object>>[] objectPaths)
63+
{
64+
this._Mapping.CopyTo = objectPaths.Select(e => (PropertyPathMarker)e);
65+
return this;
66+
}
5667
}
5768
}

Diff for: src/Nest/Domain/Mapping/Descriptors/StringMappingDescriptor.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using System;
2+
using System.Linq;
23
using System.Linq.Expressions;
34
using Nest.Resolvers;
45

@@ -92,5 +93,16 @@ public StringMappingDescriptor<T> PositionOffsetGap(int positionOffsetGap)
9293
return this;
9394
}
9495

96+
public StringMappingDescriptor<T> CopyTo(params string[] fields)
97+
{
98+
this._Mapping.CopyTo = fields.Select(f => (PropertyPathMarker)f);
99+
return this;
100+
}
101+
102+
public StringMappingDescriptor<T> CopyTo(params Expression<Func<T, object>>[] objectPaths)
103+
{
104+
this._Mapping.CopyTo = objectPaths.Select(e => (PropertyPathMarker)e);
105+
return this;
106+
}
95107
}
96108
}

Diff for: src/Nest/Domain/Mapping/Types/BinaryMapping.cs

+3
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@ public class BinaryMapping : IElasticType, IElasticCoreType
2424
/// </summary>
2525
[JsonProperty("index_name")]
2626
public string IndexName { get; set; }
27+
28+
[JsonProperty("copy_to")]
29+
public IEnumerable<PropertyPathMarker> CopyTo { get; set; }
2730
}
2831
}

Diff for: src/Nest/Domain/Mapping/Types/BooleanMapping.cs

+2
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,7 @@ public class BooleanMapping : IElasticType, IElasticCoreType
4040
[JsonProperty("include_in_all")]
4141
public bool? IncludeInAll { get; set; }
4242

43+
[JsonProperty("copy_to")]
44+
public IEnumerable<PropertyPathMarker> CopyTo { get; set; }
4345
}
4446
}

Diff for: src/Nest/Domain/Mapping/Types/StringMapping.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ public class StringMapping : IElasticType, IElasticCoreType
6262
public bool? IncludeInAll { get; set; }
6363

6464
[JsonProperty("position_offset_gap")]
65-
public int? PositionOffsetGap { get; set; }
66-
65+
public int? PositionOffsetGap { get; set; }
66+
67+
[JsonProperty("copy_to")]
68+
public IEnumerable<PropertyPathMarker> CopyTo { get; set; }
6769
}
6870
}

Diff for: src/Tests/Nest.Tests.Unit/Core/Map/FluentMappingFullExampleTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public void MapFluentFull()
138138
.Store()
139139
.TermVector(TermVectorOption.with_positions_offsets)
140140
.Boost(1.1)
141+
.CopyTo(p => p.Content)
141142
)
142143
.Number(s => s
143144
.Name(p => p.LOC)
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
{
2-
"elasticsearchprojects": {
3-
"properties": {
4-
"myBinaryField": {
5-
"type": "binary",
6-
"index_name": "binz"
7-
}
8-
}
9-
}
10-
}
1+
{
2+
"elasticsearchprojects": {
3+
"properties": {
4+
"myBinaryField": {
5+
"type": "binary",
6+
"index_name": "binz",
7+
"copy_to": [ "another_field" ]
8+
}
9+
}
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
{
2-
"elasticsearchprojects": {
3-
"properties": {
4-
"boolValue": {
5-
"type": "boolean",
6-
"index_name": "bool_name_in_lucene_index",
7-
"store": "yes",
8-
"index": "analyzed",
9-
"boost": 1.4,
10-
"null_value": false,
11-
"include_in_all": true
12-
}
13-
}
14-
}
15-
}
1+
{
2+
"elasticsearchprojects": {
3+
"properties": {
4+
"boolValue": {
5+
"type": "boolean",
6+
"index_name": "bool_name_in_lucene_index",
7+
"store": "yes",
8+
"index": "analyzed",
9+
"boost": 1.4,
10+
"null_value": false,
11+
"include_in_all": true,
12+
"copy_to": [ "content" ]
13+
}
14+
}
15+
}
16+
}

Diff for: src/Tests/Nest.Tests.Unit/Core/Map/Properties/PropertiesTests.cs

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public void StringProperty()
2828
.Store()
2929
.TermVector(TermVectorOption.with_positions_offsets)
3030
.Boost(1.1)
31+
.CopyTo(p => p.Content, p => p.Country)
3132
)
3233
)
3334
);
@@ -88,6 +89,7 @@ public void BooleanProperty()
8889
.IndexName("bool_name_in_lucene_index")
8990
.NullValue(false)
9091
.Store()
92+
.CopyTo(p => p.Content)
9193
)
9294
)
9395
);
@@ -101,6 +103,7 @@ public void BinaryProperty()
101103
.Binary(s => s
102104
.Name(p => p.MyBinaryField)
103105
.IndexName("binz")
106+
.CopyTo("another_field")
104107
)
105108
)
106109
);
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
{
2-
"elasticsearchprojects": {
3-
"properties": {
4-
"name": {
5-
"type": "string",
6-
"index_name": "my_crazy_name_i_want_in_lucene",
7-
"store": "yes",
8-
"index": "analyzed",
9-
"term_vector": "with_positions_offsets",
10-
"boost": 1.1,
11-
"null_value": "my_special_null_value",
12-
"omit_norms": true,
13-
"index_options": "positions",
14-
"index_analyzer": "standard",
15-
"search_analyzer": "standard",
16-
"include_in_all": true,
17-
"position_offset_gap": 1
18-
}
19-
}
20-
}
21-
}
1+
{
2+
"elasticsearchprojects": {
3+
"properties": {
4+
"name": {
5+
"type": "string",
6+
"index_name": "my_crazy_name_i_want_in_lucene",
7+
"store": "yes",
8+
"index": "analyzed",
9+
"term_vector": "with_positions_offsets",
10+
"boost": 1.1,
11+
"null_value": "my_special_null_value",
12+
"omit_norms": true,
13+
"index_options": "positions",
14+
"index_analyzer": "standard",
15+
"search_analyzer": "standard",
16+
"include_in_all": true,
17+
"position_offset_gap": 1,
18+
"copy_to": [ "content", "country" ]
19+
}
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)