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

File tree

12 files changed

+102
-49
lines changed

12 files changed

+102
-49
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
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

src/Nest/Domain/Mapping/Descriptors/BinaryMappingDescriptor.cs

Lines changed: 12 additions & 0 deletions
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
}

src/Nest/Domain/Mapping/Descriptors/BooleanMappingDescriptor.cs

Lines changed: 11 additions & 0 deletions
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
}

src/Nest/Domain/Mapping/Descriptors/StringMappingDescriptor.cs

Lines changed: 13 additions & 1 deletion
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
}

src/Nest/Domain/Mapping/Types/BinaryMapping.cs

Lines changed: 3 additions & 0 deletions
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
}

src/Nest/Domain/Mapping/Types/BooleanMapping.cs

Lines changed: 2 additions & 0 deletions
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
}

src/Nest/Domain/Mapping/Types/StringMapping.cs

Lines changed: 4 additions & 2 deletions
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
}

src/Tests/Nest.Tests.Unit/Core/Map/FluentMappingFullExampleTests.cs

Lines changed: 1 addition & 0 deletions
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)
Lines changed: 11 additions & 10 deletions
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+
}
Lines changed: 16 additions & 15 deletions
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+
}

0 commit comments

Comments
 (0)