Skip to content

Commit e02ce22

Browse files
committed
Update mappings to allow inheritance for multifieldmap
1 parent 8d1c8be commit e02ce22

File tree

6 files changed

+25
-60
lines changed

6 files changed

+25
-60
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66
namespace Nest
77
{
88
[JsonObject(MemberSerialization.OptIn)]
9-
public class BooleanMapping : IElasticType, IElasticCoreType
9+
public class BooleanMapping : MultiFieldMapping, IElasticType, IElasticCoreType
1010
{
11-
12-
public PropertyNameMarker Name { get; set; }
13-
14-
[JsonProperty("type")]
15-
public virtual TypeNameMarker Type { get { return new TypeNameMarker { Name = "boolean" }; } }
16-
17-
[JsonProperty("similarity")]
18-
public string Similarity { get; set; }
11+
public BooleanMapping()
12+
{
13+
Type = "boolean";
14+
}
1915

2016
/// <summary>
2117
/// The name of the field that will be stored in the index. Defaults to the property/field name.
@@ -35,9 +31,6 @@ public class BooleanMapping : IElasticType, IElasticCoreType
3531
[JsonProperty("null_value")]
3632
public bool? NullValue { get; set; }
3733

38-
[JsonProperty("include_in_all")]
39-
public bool? IncludeInAll { get; set; }
40-
4134
[JsonProperty("copy_to")]
4235
public IEnumerable<PropertyPathMarker> CopyTo { get; set; }
4336
}

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
namespace Nest
77
{
88
[JsonObject(MemberSerialization.OptIn)]
9-
public class DateMapping : IElasticType, IElasticCoreType
9+
public class DateMapping : MultiFieldMapping, IElasticType, IElasticCoreType
1010
{
11-
public PropertyNameMarker Name { get; set; }
12-
13-
[JsonProperty("type")]
14-
public virtual TypeNameMarker Type { get { return new TypeNameMarker { Name = "date" }; } }
15-
16-
[JsonProperty("similarity")]
17-
public string Similarity { get; set; }
11+
public DateMapping()
12+
{
13+
Type = "date";
14+
}
1815

1916
/// <summary>
2017
/// The name of the field that will be stored in the index. Defaults to the property/field name.
@@ -40,9 +37,6 @@ public class DateMapping : IElasticType, IElasticCoreType
4037
[JsonProperty("null_value")]
4138
public DateTime? NullValue { get; set; }
4239

43-
[JsonProperty("include_in_all")]
44-
public bool? IncludeInAll { get; set; }
45-
4640
[JsonProperty("ignore_malformed")]
4741
public bool? IgnoreMalformed { get; set; }
4842

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public virtual TypeNameMarker Type
2828
[JsonProperty("include_in_all")]
2929
public bool? IncludeInAll { get; set; }
3030

31-
[JsonProperty("fields"), JsonConverter(typeof(ElasticCoreTypeConverter))]
31+
[JsonProperty("fields", DefaultValueHandling = DefaultValueHandling.Ignore), JsonConverter(typeof(ElasticCoreTypeConverter))]
3232
public IDictionary<PropertyNameMarker, IElasticCoreType> Fields { get; set; }
3333

3434

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55

66
namespace Nest
77
{
8-
[JsonObject(MemberSerialization.OptIn)]
9-
public class NumberMapping : IElasticType, IElasticCoreType
10-
{
11-
public PropertyNameMarker Name { get; set; }
12-
13-
private TypeNameMarker __type;
14-
[JsonProperty("type")]
15-
public virtual TypeNameMarker Type { get { return (TypeNameMarker)(__type ?? "double"); } set { __type = value; } }
16-
17-
[JsonProperty("similarity")]
18-
public string Similarity { get; set; }
8+
[JsonObject(MemberSerialization.OptIn)]
9+
public class NumberMapping : MultiFieldMapping, IElasticType, IElasticCoreType
10+
{
11+
public NumberMapping()
12+
{
13+
Type = "double";
14+
}
1915

2016
/// <summary>
2117
/// The name of the field that will be stored in the index. Defaults to the property/field name.
@@ -41,9 +37,6 @@ public class NumberMapping : IElasticType, IElasticCoreType
4137
[JsonProperty("doc_values")]
4238
public bool? DocValues { get; set; }
4339

44-
[JsonProperty("include_in_all")]
45-
public bool? IncludeInAll { get; set; }
46-
4740
[JsonProperty("ignore_malformed")]
4841
public bool? IgnoreMalformed { get; set; }
4942

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66
namespace Nest
77
{
88
[JsonObject(MemberSerialization.OptIn)]
9-
public class StringMapping : IElasticType, IElasticCoreType
10-
{
11-
[JsonProperty("type")]
12-
public virtual TypeNameMarker Type { get { return new TypeNameMarker { Name = "string" }; } }
13-
14-
//[JsonProperty(PropertyName = "name")]
15-
public PropertyNameMarker Name { get; set; }
16-
17-
[JsonProperty("similarity")]
18-
public string Similarity { get; set; }
9+
public class StringMapping : MultiFieldMapping, IElasticType, IElasticCoreType
10+
{
11+
public StringMapping()
12+
{
13+
Type = "string";
14+
}
1915

2016
/// <summary>
2117
/// The name of the field that will be stored in the index. Defaults to the property/field name.
@@ -62,9 +58,6 @@ public class StringMapping : IElasticType, IElasticCoreType
6258
[JsonProperty("doc_values")]
6359
public bool? DocValues { get; set; }
6460

65-
[JsonProperty("include_in_all")]
66-
public bool? IncludeInAll { get; set; }
67-
6861
[JsonProperty("position_offset_gap")]
6962
public int? PositionOffsetGap { get; set; }
7063

src/Nest/Resolvers/Converters/ElasticTypeConverter.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ private IElasticType GetTypeFromJObject(JObject po, JsonSerializer serializer)
2222
{
2323
JToken typeToken;
2424
JToken propertiesToken;
25-
JToken fieldsToken;
2625
var type = string.Empty;
2726

2827
var hasType = po.TryGetValue("type", out typeToken);
@@ -31,11 +30,6 @@ private IElasticType GetTypeFromJObject(JObject po, JsonSerializer serializer)
3130
else if (po.TryGetValue("properties", out propertiesToken))
3231
type = "object";
3332

34-
var originalType = type;
35-
var hasFields = po.TryGetValue("fields", out fieldsToken);
36-
if (hasFields)
37-
type = "multi_field";
38-
3933
serializer.TypeNameHandling = TypeNameHandling.None;
4034

4135
switch (type)
@@ -60,9 +54,7 @@ private IElasticType GetTypeFromJObject(JObject po, JsonSerializer serializer)
6054
case "nested":
6155
return serializer.Deserialize(po.CreateReader(), typeof(NestedObjectMapping)) as NestedObjectMapping;
6256
case "multi_field":
63-
var m =serializer.Deserialize(po.CreateReader(), typeof(MultiFieldMapping)) as MultiFieldMapping;
64-
m.Type = originalType;
65-
return m;
57+
return serializer.Deserialize(po.CreateReader(), typeof(MultiFieldMapping)) as MultiFieldMapping;
6658
case "ip":
6759
return serializer.Deserialize(po.CreateReader(), typeof(IPMapping)) as IPMapping;
6860
case "geo_point":

0 commit comments

Comments
 (0)