Skip to content

Commit 9c7e599

Browse files
committed
Fix #3323 Add support for null_value, ignore_z_value on GeoPoint prop… (#3364)
This commit adds support for null_value, ignore_z_value on GeoPoint property
1 parent 93400ac commit 9c7e599

11 files changed

+98
-16
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
namespace Nest
22
{
3+
/// <summary>
4+
/// A document field mapping in Elasticsearch
5+
/// </summary>
36
public interface IFieldMapping { }
47
}

src/Nest/Mapping/Types/CorePropertyBase.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace Nest
66
{
7+
/// <summary>
8+
/// Core properties of a mapping for a property type to a document field in Elasticsearch
9+
/// </summary>
710
[JsonObject(MemberSerialization.OptIn)]
811
[ContractJsonConverter(typeof(PropertyJsonConverter))]
912
public interface ICoreProperty : IProperty
@@ -20,13 +23,14 @@ public interface ICoreProperty : IProperty
2023

2124
/// <summary>
2225
/// Configures multi-fields for this field. Allows one field to be indexed in different
23-
/// ways to serve different purposes
26+
/// ways to serve different search and analytics purposes
2427
/// </summary>
2528
[JsonProperty("fields", DefaultValueHandling = DefaultValueHandling.Ignore)]
2629
IProperties Fields { get; set; }
2730

2831
/// <summary>
29-
/// Which relevancy scoring algorithm or similarity should be used. Defaults to BM25
32+
/// Which relevancy scoring algorithm or similarity should be used.
33+
/// Defaults to <see cref="SimilarityOption.BM25"/>
3034
/// </summary>
3135
[JsonProperty("similarity")]
3236
Union<SimilarityOption, string> Similarity { get; set; }
@@ -40,6 +44,7 @@ public interface ICoreProperty : IProperty
4044
Fields CopyTo { get; set; }
4145
}
4246

47+
/// <inheritdoc cref="ICoreProperty"/>
4348
[DebuggerDisplay("{DebugDisplay}")]
4449
public abstract class CorePropertyBase : PropertyBase, ICoreProperty
4550
{

src/Nest/Mapping/Types/CorePropertyDescriptorBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Nest
55
{
6+
/// <inheritdoc cref="ICoreProperty"/>
67
public abstract class CorePropertyDescriptorBase<TDescriptor, TInterface, T>
78
: PropertyDescriptorBase<TDescriptor, TInterface, T>, ICoreProperty
89
where TDescriptor : CorePropertyDescriptorBase<TDescriptor, TInterface, T>, TInterface
@@ -16,14 +17,19 @@ public abstract class CorePropertyDescriptorBase<TDescriptor, TInterface, T>
1617

1718
protected CorePropertyDescriptorBase(FieldType type) : base(type) {}
1819

20+
/// <inheritdoc cref="ICoreProperty.Store"/>
1921
public TDescriptor Store(bool? store = true) => Assign(a => a.Store = store);
2022

23+
/// <inheritdoc cref="ICoreProperty.Fields"/>
2124
public TDescriptor Fields(Func<PropertiesDescriptor<T>, IPromise<IProperties>> selector) => Assign(a => a.Fields = selector?.Invoke(new PropertiesDescriptor<T>())?.Value);
2225

26+
/// <inheritdoc cref="ICoreProperty.Similarity"/>
2327
public TDescriptor Similarity(SimilarityOption? similarity) => Assign(a => a.Similarity = similarity);
2428

29+
/// <inheritdoc cref="ICoreProperty.Similarity"/>
2530
public TDescriptor Similarity(string similarity) => Assign(a => a.Similarity = similarity);
2631

32+
/// <inheritdoc cref="ICoreProperty.CopyTo"/>
2733
public TDescriptor CopyTo(Func<FieldsDescriptor<T>, IPromise<Fields>> fields) => Assign(a => a.CopyTo = fields?.Invoke(new FieldsDescriptor<T>())?.Value);
2834
}
2935
}

src/Nest/Mapping/Types/DocValuesPropertyBase.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,27 @@
44

55
namespace Nest
66
{
7+
/// <summary>
8+
/// Properties of a mapping for a property type to a document field that has doc_values in Elasticsearch
9+
/// </summary>
710
[JsonObject(MemberSerialization.OptIn)]
811
[ContractJsonConverter(typeof(PropertyJsonConverter))]
912
public interface IDocValuesProperty : ICoreProperty
1013
{
14+
/// <summary>
15+
/// Whether to persist the value at index time in a columnar data structure (referred to as doc_values in Lucene)
16+
/// which makes the value available for efficient sorting and aggregations. Default is <c>true</c>.
17+
/// </summary>
1118
[JsonProperty("doc_values")]
1219
bool? DocValues { get; set; }
1320
}
1421

22+
/// <inheritdoc cref="IDocValuesProperty"/>
1523
public abstract class DocValuesPropertyBase : CorePropertyBase, IDocValuesProperty
1624
{
1725
protected DocValuesPropertyBase(FieldType type) : base(type) { }
1826

27+
/// <inheritdoc />
1928
public bool? DocValues { get; set; }
2029
}
2130
}

src/Nest/Mapping/Types/DocValuesPropertyDescriptorBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Nest
55
{
6+
/// <inheritdoc cref="IDocValuesProperty"/>
67
public abstract class DocValuesPropertyDescriptorBase<TDescriptor, TInterface, T>
78
: CorePropertyDescriptorBase<TDescriptor, TInterface, T>, IDocValuesProperty
89
where TDescriptor : DocValuesPropertyDescriptorBase<TDescriptor, TInterface, T>, TInterface
@@ -13,6 +14,7 @@ public abstract class DocValuesPropertyDescriptorBase<TDescriptor, TInterface, T
1314

1415
protected DocValuesPropertyDescriptorBase(FieldType type) : base(type) { }
1516

17+
/// <inheritdoc cref="IDocValuesProperty.DocValues"/>
1618
public TDescriptor DocValues(bool? docValues = true) => Assign(a => a.DocValues = docValues);
1719
}
1820
}

src/Nest/Mapping/Types/Geo/GeoPoint/GeoPointAttribute.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ public class GeoPointAttribute : ElasticsearchDocValuesPropertyAttributeBase, IG
77
public GeoPointAttribute() : base(FieldType.GeoPoint) { }
88

99
bool? IGeoPointProperty.IgnoreMalformed { get; set; }
10+
bool? IGeoPointProperty.IgnoreZValue { get; set; }
11+
GeoLocation IGeoPointProperty.NullValue { get; set; }
1012

11-
public bool IgnoreMalformed { get { return Self.IgnoreMalformed.GetValueOrDefault(); } set { Self.IgnoreMalformed = value; } }
13+
/// <inheritdoc cref="IGeoPointProperty.IgnoreMalformed"/>
14+
public bool IgnoreMalformed { get => Self.IgnoreMalformed.GetValueOrDefault(); set => Self.IgnoreMalformed = value; }
15+
16+
/// <inheritdoc cref="IGeoPointProperty.IgnoreZValue"/>
17+
public bool IgnoreZValue { get => Self.IgnoreZValue.GetValueOrDefault(true); set => Self.IgnoreZValue= value; }
1218
}
1319
}

src/Nest/Mapping/Types/Geo/GeoPoint/GeoPointProperty.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,50 @@
44

55
namespace Nest
66
{
7+
/// <summary>
8+
/// Data type mapping to map a property as a geopoint
9+
/// </summary>
710
[JsonObject(MemberSerialization.OptIn)]
811
public interface IGeoPointProperty : IDocValuesProperty
912
{
13+
/// <summary>
14+
/// If true, malformed geo-points are ignored. If false (default), malformed
15+
/// geo-points throw an exception and reject the whole document.
16+
/// </summary>
1017
[JsonProperty("ignore_malformed")]
1118
bool? IgnoreMalformed { get; set; }
19+
20+
21+
/// <summary>
22+
/// If true (default) three dimension points will be accepted (stored in source) but only
23+
/// latitude and longitude values will be indexed; the third dimension is ignored. If false, geo-points
24+
/// containing any more than latitude and longitude (two dimensions) values
25+
/// throw an exception and reject the whole document.
26+
/// </summary>
27+
[JsonProperty("ignore_z_value")]
28+
bool? IgnoreZValue { get; set; }
29+
30+
/// <summary>
31+
/// Accepts a geo_point value which is substituted for any explicit null values.
32+
/// Defaults to null, which means the field is treated as missing.
33+
/// </summary>
34+
[JsonProperty("null_value")]
35+
GeoLocation NullValue { get; set; }
1236
}
1337

1438
[DebuggerDisplay("{DebugDisplay}")]
1539
public class GeoPointProperty : DocValuesPropertyBase, IGeoPointProperty
1640
{
1741
public GeoPointProperty() : base(FieldType.GeoPoint) { }
1842

43+
/// <inheritdoc />
1944
public bool? IgnoreMalformed { get; set; }
45+
46+
/// <inheritdoc />
47+
public bool? IgnoreZValue { get; set; }
48+
49+
/// <inheritdoc />
50+
public GeoLocation NullValue { get; set; }
2051
}
2152

2253
[DebuggerDisplay("{DebugDisplay}")]
@@ -25,9 +56,18 @@ public class GeoPointPropertyDescriptor<T>
2556
where T : class
2657
{
2758
bool? IGeoPointProperty.IgnoreMalformed { get; set; }
59+
bool? IGeoPointProperty.IgnoreZValue { get; set; }
60+
GeoLocation IGeoPointProperty.NullValue { get; set; }
2861

2962
public GeoPointPropertyDescriptor() : base(FieldType.GeoPoint) { }
3063

64+
/// <inheritdoc cref="IGeoPointProperty.IgnoreMalformed" />
3165
public GeoPointPropertyDescriptor<T> IgnoreMalformed(bool? ignoreMalformed = true) => Assign(a => a.IgnoreMalformed = ignoreMalformed);
66+
67+
/// <inheritdoc cref="IGeoPointProperty.IgnoreZValue" />
68+
public GeoPointPropertyDescriptor<T> IgnoreZValue(bool? ignoreZValue = true) => Assign(a => a.IgnoreZValue = ignoreZValue);
69+
70+
/// <inheritdoc cref="IGeoPointProperty.NullValue" />
71+
public GeoPointPropertyDescriptor<T> NullValue(GeoLocation defaultValue) => Assign(a => a.NullValue = defaultValue);
3272
}
3373
}

src/Nest/Mapping/Types/Properties.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public partial interface IPropertiesDescriptor<T, out TReturnType>
4949
TReturnType Text(Func<TextPropertyDescriptor<T>, ITextProperty> selector);
5050
TReturnType Keyword(Func<KeywordPropertyDescriptor<T>, IKeywordProperty> selector);
5151
/// <summary>
52-
/// Number introduces a numeric mapping that defaults to `float` use .Type() to set the right type if needed or use
52+
/// Number introduces a numeric mapping that defaults to `float`. Use .Type() to set the right type if needed or use
5353
/// Scalar instead of <see cref="Number"/>
5454
/// </summary>
5555
TReturnType Number(Func<NumberPropertyDescriptor<T>, INumberProperty> selector);

src/Nest/Mapping/Types/PropertyBase.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
namespace Nest
99
{
10+
/// <summary>
11+
/// A mapping for a property type to a document field in Elasticsearch
12+
/// </summary>
1013
[JsonObject(MemberSerialization.OptIn)]
1114
[ContractJsonConverter(typeof(PropertyJsonConverter))]
1215
public interface IProperty : IFieldMapping
@@ -29,25 +32,32 @@ public interface IProperty : IFieldMapping
2932
IDictionary<string, object> LocalMetadata { get; set; }
3033
}
3134

35+
/// <summary>
36+
/// A mapping for a property from a CLR type
37+
/// </summary>
3238
public interface IPropertyWithClrOrigin
3339
{
40+
/// <summary>
41+
/// The CLR property to which the mapping relates
42+
/// </summary>
3443
PropertyInfo ClrOrigin { get; set; }
3544
}
3645

46+
/// <inheritdoc cref="IProperty"/>
3747
[DebuggerDisplay("{DebugDisplay}")]
3848
public abstract class PropertyBase : IProperty, IPropertyWithClrOrigin
3949
{
4050
private string _type;
41-
protected string TypeOverride { get => _type; set => _type = value; }
4251

4352
string IProperty.Type { get => _type; set => _type = value; }
44-
4553
PropertyInfo IPropertyWithClrOrigin.ClrOrigin { get; set; }
4654

47-
protected PropertyBase(FieldType type)
48-
{
49-
((IProperty)this).Type = type.GetStringValue();
50-
}
55+
protected PropertyBase(FieldType type) => ((IProperty)this).Type = type.GetStringValue();
56+
57+
/// <summary>
58+
/// Override for the property type, used for custom mappings
59+
/// </summary>
60+
protected string TypeOverride { get => _type; set => _type = value; }
5161

5262
protected string DebugDisplay => $"Type: {((IProperty)this).Type ?? "<empty>"}, Name: {Name.DebugDisplay} ";
5363

src/Nest/Mapping/Types/PropertyDescriptorBase.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
namespace Nest
77
{
8+
/// <inheritdoc cref="IProperty"/>
89
public abstract class PropertyDescriptorBase<TDescriptor, TInterface, T>
910
: DescriptorBase<TDescriptor, TInterface>, IProperty
1011
where TDescriptor : PropertyDescriptorBase<TDescriptor, TInterface, T>, TInterface
@@ -21,13 +22,13 @@ public abstract class PropertyDescriptorBase<TDescriptor, TInterface, T>
2122

2223
protected PropertyDescriptorBase(FieldType type) { Self.Type = type.GetStringValue(); }
2324

25+
/// <inheritdoc cref="IProperty.Name"/>
2426
public TDescriptor Name(PropertyName name) => Assign(a => a.Name = name);
2527

28+
/// <inheritdoc cref="IProperty.Name"/>
2629
public TDescriptor Name(Expression<Func<T, object>> objectPath) => Assign(a => a.Name = objectPath);
2730

28-
/// <summary>
29-
/// Local property metadata that will NOT be stored in Elasticsearch with the mappings
30-
/// </summary>
31+
/// <inheritdoc cref="IProperty.LocalMetadata"/>
3132
public TDescriptor LocalMetadata(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector) =>
3233
Assign(a => a.LocalMetadata = selector?.Invoke(new FluentDictionary<string, object>()));
3334
}

src/Tests/Tests/Mapping/Types/Geo/GeoPoint/GeoPointAttributeTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ namespace Tests.Mapping.Types.Geo.GeoPoint
55
{
66
public class GeoPointTest
77
{
8-
[GeoPoint(
9-
IgnoreMalformed = true)]
8+
[GeoPoint(IgnoreMalformed = true, IgnoreZValue = true)]
109
public string Full { get; set; }
1110

1211
[GeoPoint]
@@ -24,7 +23,8 @@ public class GeoPointAttributeTests : AttributeTestsBase<GeoPointTest>
2423
full = new
2524
{
2625
type = "geo_point",
27-
ignore_malformed = true
26+
ignore_malformed = true,
27+
ignore_z_value = true
2828
},
2929
minimal = new
3030
{

0 commit comments

Comments
 (0)