Skip to content

Commit 1fb762e

Browse files
committed
Deserialize copy_to on mapping
Ensure that all mapping types can be serialized and deserialized. Fixes #2409
1 parent 5fbb1dc commit 1fb762e

File tree

12 files changed

+105
-2
lines changed

12 files changed

+105
-2
lines changed

src/Nest/CommonAbstractions/Infer/Field/Field.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ string IUrlParameter.GetString(IConnectionConfigurationValues settings)
125125
{
126126
var nestSettings = settings as IConnectionSettingsValues;
127127
if (nestSettings == null)
128-
throw new Exception("Tried to pass field name on querysting but it could not be resolved because no nest settings are available");
128+
throw new Exception("Tried to pass field name on querystring but it could not be resolved because no nest settings are available");
129129

130130
return nestSettings.Inferrer.Field(this);
131131
}

src/Nest/Mapping/Types/CorePropertyBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public interface ICoreProperty : IProperty
1616
Union<SimilarityOption, string> Similarity { get; set; }
1717

1818
[JsonProperty("copy_to")]
19+
[JsonConverter(typeof(FieldsJsonConverter))]
1920
Fields CopyTo { get; set; }
2021
}
2122

src/Nest/Modules/Indices/Fielddata/FielddataFilter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Nest
55
{
66
[JsonObject(MemberSerialization.OptIn)]
7+
[JsonConverter(typeof(ReadAsTypeJsonConverter<FielddataFilter>))]
78
public interface IFielddataFilter
89
{
910
[JsonProperty("frequency")]

src/Nest/Modules/Indices/Fielddata/FielddataFrequencyFilter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Nest
44
{
55
[JsonObject(MemberSerialization.OptIn)]
6+
[JsonConverter(typeof(ReadAsTypeJsonConverter<FielddataFrequencyFilter>))]
67
public interface IFielddataFrequencyFilter
78
{
89
[JsonProperty("min")]

src/Nest/Modules/Indices/Fielddata/FielddataRegexFilter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Nest
44
{
55
[JsonObject(MemberSerialization.OptIn)]
6+
[JsonConverter(typeof(ReadAsTypeJsonConverter<FielddataRegexFilter>))]
67
public interface IFielddataRegexFilter
78
{
89
[JsonProperty("pattern")]

src/Nest/Modules/Indices/Fielddata/Numeric/NumericFielddata.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Nest
44
{
55
[JsonObject(MemberSerialization.OptIn)]
6+
[JsonConverter(typeof(ReadAsTypeJsonConverter<NumericFielddata>))]
67
public interface INumericFielddata : IFielddata
78
{
89
[JsonProperty("format")]

src/Nest/Modules/Indices/Fielddata/Numeric/NumericFielddataFormat.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using System.Runtime.Serialization;
2+
using Newtonsoft.Json;
3+
using Newtonsoft.Json.Converters;
24

35
namespace Nest
46
{
7+
[JsonConverter(typeof(StringEnumConverter))]
58
public enum NumericFielddataFormat
69
{
710
[EnumMember(Value = "array")]

src/Nest/Modules/Indices/Fielddata/String/StringFielddata.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Nest
44
{
55
[JsonObject(MemberSerialization.OptIn)]
6+
[JsonConverter(typeof(ReadAsTypeJsonConverter<StringFielddata>))]
67
public interface IStringFielddata : IFielddata
78
{
89
[JsonProperty("format")]

src/Tests/Mapping/Types/Core/Text/TextPropertyTests.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,23 @@ public TextPropertyTests(WritableCluster cluster, EndpointUsage usage) : base(cl
2020
type = "text",
2121
analyzer = "standard",
2222
boost = 1.2,
23+
copy_to = new [] { "other_field" },
2324
eager_global_ordinals = true,
2425
fielddata = true,
26+
fielddata_frequency_filter = new
27+
{
28+
min = 1.0,
29+
max = 100.00,
30+
min_segment_size = 2
31+
},
32+
fields = new
33+
{
34+
raw = new
35+
{
36+
type = "keyword",
37+
ignore_above = 100
38+
}
39+
},
2540
include_in_all = false,
2641
index = true,
2742
index_options = "offsets",
@@ -41,8 +56,22 @@ public TextPropertyTests(WritableCluster cluster, EndpointUsage usage) : base(cl
4156
.Name(p => p.Name)
4257
.Analyzer("standard")
4358
.Boost(1.2)
59+
.CopyTo(c => c
60+
.Field("other_field")
61+
)
4462
.EagerGlobalOrdinals()
4563
.Fielddata()
64+
.FielddataFrequencyFilter(ff => ff
65+
.Min(1)
66+
.Max(100)
67+
.MinSegmentSize(2)
68+
)
69+
.Fields(fd => fd
70+
.Keyword(k => k
71+
.Name("raw")
72+
.IgnoreAbove(100)
73+
)
74+
)
4675
.IncludeInAll(false)
4776
.Index(true)
4877
.IndexOptions(IndexOptions.Offsets)
@@ -61,8 +90,23 @@ public TextPropertyTests(WritableCluster cluster, EndpointUsage usage) : base(cl
6190
{
6291
Analyzer = "standard",
6392
Boost = 1.2,
93+
CopyTo = "other_field",
6494
EagerGlobalOrdinals = true,
6595
Fielddata = true,
96+
FielddataFrequencyFilter = new FielddataFrequencyFilter
97+
{
98+
Min = 1,
99+
Max = 100,
100+
MinSegmentSize = 2
101+
},
102+
Fields = new Properties
103+
{
104+
{ "raw", new KeywordProperty
105+
{
106+
IgnoreAbove = 100
107+
}
108+
}
109+
},
66110
IncludeInAll = false,
67111
Index = true,
68112
IndexOptions = IndexOptions.Offsets,
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Linq;
3+
using System.Text;
4+
using Elasticsearch.Net;
5+
using FluentAssertions;
6+
using Nest;
7+
using Tests.Framework;
8+
using Tests.Indices.MappingManagement.GetMapping;
9+
using Xunit;
10+
11+
namespace Tests.Reproduce
12+
{
13+
public class GithubIssue2409
14+
{
15+
[U]
16+
public void CanDeserializeCopyTo()
17+
{
18+
var json = "{\"test-events-v1-201412\":{\"mappings\":{\"events\":{\"dynamic\":\"false\",\"_size\":{\"enabled\":true},\"properties\":{\"created_utc\":{\"type\":\"date\"},\"data\":{\"properties\":{\"@environment\":{\"properties\":{\"o_s_name\":{\"type\":\"text\",\"index\":false,\"copy_to\":[\"os\"]}}}}},\"id\":{\"type\":\"keyword\"},\"os\":{\"type\":\"text\",\"fields\":{\"keyword\":{\"type\":\"keyword\",\"ignore_above\":256}}}}}}},\"test-events-v1-201502\":{\"mappings\":{\"events\":{\"dynamic\":\"false\",\"_size\":{\"enabled\":true},\"properties\":{\"created_utc\":{\"type\":\"date\"},\"data\":{\"properties\":{\"@environment\":{\"properties\":{\"o_s_name\":{\"type\":\"text\",\"index\":false,\"copy_to\":[\"os\"]}}}}},\"id\":{\"type\":\"keyword\"},\"os\":{\"type\":\"text\",\"fields\":{\"keyword\":{\"type\":\"keyword\",\"ignore_above\":256}}}}}}}}";
19+
20+
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
21+
22+
var connection = new InMemoryConnection(Encoding.UTF8.GetBytes(json));
23+
var settings = new ConnectionSettings(pool, connection).DefaultIndex("test-events-v1-201412");
24+
var client = new ElasticClient(settings);
25+
26+
var mappingResponse = client.GetMapping<Events>();
27+
28+
mappingResponse.IsValid.Should().BeTrue();
29+
30+
var mappingWalker = new MappingWalker(new CopyToVisitor());
31+
mappingWalker.Accept(mappingResponse);
32+
}
33+
34+
public class CopyToVisitor : NoopMappingVisitor
35+
{
36+
public override void Visit(ITextProperty property)
37+
{
38+
if (property.Name == "o_s_name")
39+
{
40+
property.CopyTo.Should().NotBeNull();
41+
}
42+
}
43+
}
44+
45+
public class Events
46+
{
47+
}
48+
}
49+
}

src/Tests/Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@
624624
<Compile Include="Reproduce\GithubIssue2306.cs" />
625625
<Compile Include="Reproduce\GithubIssue2309.cs" />
626626
<Compile Include="Reproduce\GithubIssue2323.cs" />
627+
<Compile Include="Reproduce\GithubIssue2409.cs" />
627628
<Compile Include="Search\Hits\HitsSerializationTests.cs" />
628629
<Compile Include="Search\MultiSearch\MultiSearchApiTests.cs" />
629630
<Compile Include="Search\MultiSearch\MultiSearchInvalidApiTests.cs" />

src/Tests/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mode either u (unit test), i (integration test) or m (mixed mode)
2-
mode: i
2+
mode: m
33
# the elasticsearch version that should be started
44
# Can be a snapshot version of sonatype or "latest" to get the latest snapshot of sonatype
55
elasticsearch_version: 5.0.1

0 commit comments

Comments
 (0)