Skip to content

Commit aa15d2e

Browse files
committed
Change mapping to use contructor for default type
1 parent b56f334 commit aa15d2e

File tree

6 files changed

+52
-49
lines changed

6 files changed

+52
-49
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ namespace Nest
88
[JsonObject(MemberSerialization.OptIn)]
99
public class BooleanMapping : MultiFieldMapping, IElasticType, IElasticCoreType
1010
{
11-
public BooleanMapping()
11+
public BooleanMapping():base("boolean")
1212
{
13-
Type = "boolean";
1413
}
1514

1615
/// <summary>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ namespace Nest
88
[JsonObject(MemberSerialization.OptIn)]
99
public class DateMapping : MultiFieldMapping, IElasticType, IElasticCoreType
1010
{
11-
public DateMapping()
11+
public DateMapping():base("date")
1212
{
13-
Type = "date";
1413
}
1514

1615
/// <summary>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ namespace Nest
1212
[JsonObject(MemberSerialization.OptIn)]
1313
public class GenericMapping : MultiFieldMapping, IElasticType, IElasticCoreType
1414
{
15-
public GenericMapping()
15+
public GenericMapping():base(null)
1616
{
17-
Type = string.Empty;
1817
}
1918

2019
/// <summary>

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,27 @@ namespace Nest
88
[JsonObject(MemberSerialization.OptIn)]
99
public class MultiFieldMapping : IElasticType
1010
{
11+
private readonly TypeNameMarker _defaultType;
12+
13+
public MultiFieldMapping()
14+
: this("multi_field")
15+
{
16+
this.Fields = new Dictionary<PropertyNameMarker, IElasticCoreType>();
17+
}
18+
19+
protected MultiFieldMapping(TypeNameMarker defaultType)
20+
{
21+
_defaultType = defaultType;
22+
}
23+
1124
public PropertyNameMarker Name { get; set; }
1225

1326
private TypeNameMarker _typeOverride;
1427

1528
[JsonProperty("type")]
1629
public virtual TypeNameMarker Type
1730
{
18-
get { return _typeOverride ?? new TypeNameMarker { Name = "multi_field" }; }
31+
get { return _typeOverride ?? _defaultType; }
1932
set { _typeOverride = value; }
2033
}
2134

@@ -30,12 +43,6 @@ public virtual TypeNameMarker Type
3043

3144
[JsonProperty("fields", DefaultValueHandling = DefaultValueHandling.Ignore), JsonConverter(typeof(ElasticCoreTypeConverter))]
3245
public IDictionary<PropertyNameMarker, IElasticCoreType> Fields { get; set; }
33-
34-
35-
public MultiFieldMapping()
36-
{
37-
this.Fields = new Dictionary<PropertyNameMarker, IElasticCoreType>();
38-
}
3946
}
4047

4148
public class MultiFieldMappingPath
Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
using System.Collections.Generic;
2-
using Newtonsoft.Json;
3-
using System;
2+
using Newtonsoft.Json;
3+
using System;
44
using Newtonsoft.Json.Converters;
55

6-
namespace Nest
7-
{
6+
namespace Nest
7+
{
88
[JsonObject(MemberSerialization.OptIn)]
9-
public class NumberMapping : MultiFieldMapping, IElasticType, IElasticCoreType
9+
public class NumberMapping : MultiFieldMapping, IElasticType, IElasticCoreType
1010
{
1111
public NumberMapping()
12+
: base("double")
1213
{
13-
Type = "double";
1414
}
15-
16-
/// <summary>
17-
/// The name of the field that will be stored in the index. Defaults to the property/field name.
18-
/// </summary>
19-
[JsonProperty("index_name")]
20-
public string IndexName { get; set; }
21-
22-
[JsonProperty("store")]
23-
public bool? Store { get; set; }
24-
25-
[JsonProperty("index"), JsonConverter(typeof(StringEnumConverter))]
26-
public NonStringIndexOption? Index { get; set; }
27-
28-
[JsonProperty("precision_step")]
29-
public int? PrecisionStep { get; set; }
30-
31-
[JsonProperty("boost")]
32-
public double? Boost { get; set; }
33-
34-
[JsonProperty("null_value")]
35-
public double? NullValue { get; set; }
36-
15+
16+
/// <summary>
17+
/// The name of the field that will be stored in the index. Defaults to the property/field name.
18+
/// </summary>
19+
[JsonProperty("index_name")]
20+
public string IndexName { get; set; }
21+
22+
[JsonProperty("store")]
23+
public bool? Store { get; set; }
24+
25+
[JsonProperty("index"), JsonConverter(typeof(StringEnumConverter))]
26+
public NonStringIndexOption? Index { get; set; }
27+
28+
[JsonProperty("precision_step")]
29+
public int? PrecisionStep { get; set; }
30+
31+
[JsonProperty("boost")]
32+
public double? Boost { get; set; }
33+
34+
[JsonProperty("null_value")]
35+
public double? NullValue { get; set; }
36+
3737
[JsonProperty("doc_values")]
38-
public bool? DocValues { get; set; }
39-
38+
public bool? DocValues { get; set; }
39+
4040
[JsonProperty("ignore_malformed")]
4141
public bool? IgnoreMalformed { get; set; }
4242

43-
[JsonProperty("coerce")]
44-
public bool? Coerce { get; set; }
45-
46-
}
43+
[JsonProperty("coerce")]
44+
public bool? Coerce { get; set; }
45+
46+
}
4747
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ namespace Nest
88
[JsonObject(MemberSerialization.OptIn)]
99
public class StringMapping : MultiFieldMapping, IElasticType, IElasticCoreType
1010
{
11-
public StringMapping()
11+
public StringMapping():base("string")
1212
{
13-
Type = "string";
1413
}
1514

1615
/// <summary>

0 commit comments

Comments
 (0)