Skip to content

Commit 75bd162

Browse files
committed
added copy to field mapping support for appropriate types
1 parent 07bc7a6 commit 75bd162

11 files changed

+55
-6
lines changed

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)

Diff for: src/Tests/Nest.Tests.Unit/Core/Map/Properties/BinaryProperty.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"properties": {
44
"myBinaryField": {
55
"type": "binary",
6-
"index_name": "binz"
6+
"index_name": "binz",
7+
"copy_to": ["another_field"]
78
}
89
}
910
}

Diff for: src/Tests/Nest.Tests.Unit/Core/Map/Properties/BooleanProperty.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"index": "analyzed",
99
"boost": 1.4,
1010
"null_value": false,
11-
"include_in_all": true
11+
"include_in_all": true,
12+
"copy_to": ["content"]
1213
}
1314
}
1415
}

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
);

Diff for: src/Tests/Nest.Tests.Unit/Core/Map/Properties/StringProperty.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"index_analyzer": "standard",
1515
"search_analyzer": "standard",
1616
"include_in_all": true,
17-
"position_offset_gap": 1
17+
"position_offset_gap": 1,
18+
"copy_to" : ["content", "country"]
1819
}
1920
}
2021
}

0 commit comments

Comments
 (0)