Skip to content

Commit 52683cd

Browse files
committed
Add Point property for mapping point datatype
Relates: #4718, elastic/elasticsearch#53804 This commit adds a Point property to map the new point data type. A CartesianPoint type is introduced to model points.
1 parent 720dd61 commit 52683cd

File tree

22 files changed

+555
-15
lines changed

22 files changed

+555
-15
lines changed

src/Nest/Mapping/AttributeBased/ElasticsearchCorePropertyAttributeBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System;
5+
using System;
66
using System.Reflection;
77
using System.Runtime.Serialization;
88

src/Nest/Mapping/DynamicTemplate/SingleMapping.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System;
5+
using System;
66
using System.Collections.Generic;
77
using System.Linq.Expressions;
88

@@ -54,6 +54,10 @@ public IProperty GeoShape(Func<GeoShapePropertyDescriptor<T>, IGeoShapeProperty>
5454
public IProperty Shape(Func<ShapePropertyDescriptor<T>, IShapeProperty> selector) =>
5555
selector?.Invoke(new ShapePropertyDescriptor<T>());
5656

57+
/// <inheritdoc />
58+
public IProperty Point(Func<PointPropertyDescriptor<T>, IPointProperty> selector) =>
59+
selector?.Invoke(new PointPropertyDescriptor<T>());
60+
5761
/// <inheritdoc />
5862
public IProperty IntegerRange(Func<IntegerRangePropertyDescriptor<T>, IIntegerRangeProperty> selector) =>
5963
selector?.Invoke(new IntegerRangePropertyDescriptor<T>());

src/Nest/Mapping/Types/CorePropertyBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System.Diagnostics;
5+
using System.Diagnostics;
66
using System.Runtime.Serialization;
77
using Elasticsearch.Net.Utf8Json;
88

src/Nest/Mapping/Types/DocValuesPropertyBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System.Runtime.Serialization;
5+
using System.Runtime.Serialization;
66
using Elasticsearch.Net.Utf8Json;
77

88
namespace Nest

src/Nest/Mapping/Types/FieldType.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System.Runtime.Serialization;
5+
using System.Runtime.Serialization;
66
using Elasticsearch.Net;
77

88

@@ -148,6 +148,9 @@ public enum FieldType
148148
Histogram,
149149

150150
[EnumMember(Value = "constant_keyword")]
151-
ConstantKeyword
151+
ConstantKeyword,
152+
153+
[EnumMember(Value = "point")]
154+
Point,
152155
}
153156
}

src/Nest/Mapping/Types/Properties.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System;
5+
using System;
66
using System.Collections.Generic;
77
using System.Linq.Expressions;
88
using Elasticsearch.Net.Utf8Json;
@@ -95,6 +95,9 @@ TReturnType Nested<TChild>(Func<NestedPropertyDescriptor<T, TChild>, INestedProp
9595
/// <inheritdoc cref="IShapeProperty"/>
9696
TReturnType Shape(Func<ShapePropertyDescriptor<T>, IShapeProperty> selector);
9797

98+
/// <inheritdoc cref="IPointProperty"/>
99+
TReturnType Point(Func<PointPropertyDescriptor<T>, IPointProperty> selector);
100+
98101
/// <inheritdoc cref="ICompletionProperty"/>
99102
TReturnType Completion(Func<CompletionPropertyDescriptor<T>, ICompletionProperty> selector);
100103

@@ -153,42 +156,64 @@ public PropertiesDescriptor() : base(new Properties<T>()) { }
153156

154157
public PropertiesDescriptor(IProperties properties) : base(properties ?? new Properties<T>()) { }
155158

159+
/// <inheritdoc cref="IBinaryProperty"/>
156160
public PropertiesDescriptor<T> Binary(Func<BinaryPropertyDescriptor<T>, IBinaryProperty> selector) => SetProperty(selector);
157161

162+
/// <inheritdoc cref="IBooleanProperty"/>
158163
public PropertiesDescriptor<T> Boolean(Func<BooleanPropertyDescriptor<T>, IBooleanProperty> selector) => SetProperty(selector);
159164

165+
/// <inheritdoc cref="ICompletionProperty"/>
160166
public PropertiesDescriptor<T> Completion(Func<CompletionPropertyDescriptor<T>, ICompletionProperty> selector) => SetProperty(selector);
161167

168+
/// <inheritdoc cref="IDateProperty"/>
162169
public PropertiesDescriptor<T> Date(Func<DatePropertyDescriptor<T>, IDateProperty> selector) => SetProperty(selector);
163170

171+
/// <inheritdoc cref="IDateNanosProperty"/>
164172
public PropertiesDescriptor<T> DateNanos(Func<DateNanosPropertyDescriptor<T>, IDateNanosProperty> selector) => SetProperty(selector);
165173

174+
/// <inheritdoc cref="IDateRangeProperty"/>
166175
public PropertiesDescriptor<T> DateRange(Func<DateRangePropertyDescriptor<T>, IDateRangeProperty> selector) => SetProperty(selector);
167176

177+
/// <inheritdoc cref="IDoubleRangeProperty"/>
168178
public PropertiesDescriptor<T> DoubleRange(Func<DoubleRangePropertyDescriptor<T>, IDoubleRangeProperty> selector) => SetProperty(selector);
169179

180+
/// <inheritdoc cref="IFloatRangeProperty"/>
170181
public PropertiesDescriptor<T> FloatRange(Func<FloatRangePropertyDescriptor<T>, IFloatRangeProperty> selector) => SetProperty(selector);
171182

183+
/// <inheritdoc cref="IGeoPointProperty"/>
172184
public PropertiesDescriptor<T> GeoPoint(Func<GeoPointPropertyDescriptor<T>, IGeoPointProperty> selector) => SetProperty(selector);
173185

186+
/// <inheritdoc cref="IGeoShapeProperty"/>
174187
public PropertiesDescriptor<T> GeoShape(Func<GeoShapePropertyDescriptor<T>, IGeoShapeProperty> selector) => SetProperty(selector);
175188

189+
/// <inheritdoc cref="IShapeProperty"/>
176190
public PropertiesDescriptor<T> Shape(Func<ShapePropertyDescriptor<T>, IShapeProperty> selector) => SetProperty(selector);
177191

192+
/// <inheritdoc cref="IPointProperty"/>
193+
public PropertiesDescriptor<T> Point(Func<PointPropertyDescriptor<T>, IPointProperty> selector) => SetProperty(selector);
194+
195+
/// <inheritdoc cref="IIntegerRangeProperty"/>
178196
public PropertiesDescriptor<T> IntegerRange(Func<IntegerRangePropertyDescriptor<T>, IIntegerRangeProperty> selector) => SetProperty(selector);
179197

198+
/// <inheritdoc cref="IIpProperty"/>
180199
public PropertiesDescriptor<T> Ip(Func<IpPropertyDescriptor<T>, IIpProperty> selector) => SetProperty(selector);
181200

201+
/// <inheritdoc cref="IIpRangeProperty"/>
182202
public PropertiesDescriptor<T> IpRange(Func<IpRangePropertyDescriptor<T>, IIpRangeProperty> selector) => SetProperty(selector);
183203

204+
/// <inheritdoc cref="IJoinProperty"/>
184205
public PropertiesDescriptor<T> Join(Func<JoinPropertyDescriptor<T>, IJoinProperty> selector) => SetProperty(selector);
185206

207+
/// <inheritdoc cref="IKeywordProperty"/>
186208
public PropertiesDescriptor<T> Keyword(Func<KeywordPropertyDescriptor<T>, IKeywordProperty> selector) => SetProperty(selector);
187209

210+
/// <inheritdoc cref="ILongRangeProperty"/>
188211
public PropertiesDescriptor<T> LongRange(Func<LongRangePropertyDescriptor<T>, ILongRangeProperty> selector) => SetProperty(selector);
189212

213+
/// <inheritdoc cref="IMurmur3HashProperty"/>
190214
public PropertiesDescriptor<T> Murmur3Hash(Func<Murmur3HashPropertyDescriptor<T>, IMurmur3HashProperty> selector) => SetProperty(selector);
191215

216+
/// <inheritdoc cref="INestedProperty"/>
192217
public PropertiesDescriptor<T> Nested<TChild>(Func<NestedPropertyDescriptor<T, TChild>, INestedProperty> selector)
193218
where TChild : class => SetProperty(selector);
194219

@@ -199,18 +224,23 @@ public PropertiesDescriptor<T> Nested<TChild>(Func<NestedPropertyDescriptor<T, T
199224
/// </summary>
200225
public PropertiesDescriptor<T> Number(Func<NumberPropertyDescriptor<T>, INumberProperty> selector) => SetProperty(selector);
201226

227+
/// <inheritdoc cref="IObjectProperty"/>
202228
public PropertiesDescriptor<T> Object<TChild>(Func<ObjectTypeDescriptor<T, TChild>, IObjectProperty> selector)
203229
where TChild : class => SetProperty(selector);
204230

231+
/// <inheritdoc cref="IPercolatorProperty"/>
205232
public PropertiesDescriptor<T> Percolator(Func<PercolatorPropertyDescriptor<T>, IPercolatorProperty> selector) => SetProperty(selector);
206233

234+
/// <inheritdoc cref="ITextProperty"/>
207235
public PropertiesDescriptor<T> Text(Func<TextPropertyDescriptor<T>, ITextProperty> selector) => SetProperty(selector);
208236

209237
/// <inheritdoc cref="ISearchAsYouTypeProperty"/>
210238
public PropertiesDescriptor<T> SearchAsYouType(Func<SearchAsYouTypePropertyDescriptor<T>, ISearchAsYouTypeProperty> selector) => SetProperty(selector);
211239

240+
/// <inheritdoc cref="ITokenCountProperty"/>
212241
public PropertiesDescriptor<T> TokenCount(Func<TokenCountPropertyDescriptor<T>, ITokenCountProperty> selector) => SetProperty(selector);
213242

243+
/// <inheritdoc cref="IFieldAliasProperty"/>
214244
public PropertiesDescriptor<T> FieldAlias(Func<FieldAliasPropertyDescriptor<T>, IFieldAliasProperty> selector) => SetProperty(selector);
215245

216246
/// <inheritdoc cref="IRankFeatureProperty"/>
@@ -229,6 +259,9 @@ public PropertiesDescriptor<T> Object<TChild>(Func<ObjectTypeDescriptor<T, TChil
229259
public PropertiesDescriptor<T> ConstantKeyword(Func<ConstantKeywordPropertyDescriptor<T>, IConstantKeywordProperty> selector) =>
230260
SetProperty(selector);
231261

262+
/// <summary>
263+
/// Map a custom property.
264+
/// </summary>
232265
public PropertiesDescriptor<T> Custom(IProperty customType) => SetProperty(customType);
233266

234267
private PropertiesDescriptor<T> SetProperty<TDescriptor, TInterface>(Func<TDescriptor, TInterface> selector)

src/Nest/Mapping/Types/PropertyBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System.Collections.Generic;
5+
using System.Collections.Generic;
66
using System.Diagnostics;
77
using System.Reflection;
88
using System.Runtime.Serialization;

src/Nest/Mapping/Types/PropertyFormatter.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public IProperty Deserialize(ref JsonReader reader, IJsonFormatterResolver forma
8181
case FieldType.GeoPoint: return Deserialize<GeoPointProperty>(ref segmentReader, formatterResolver);
8282
case FieldType.GeoShape: return Deserialize<GeoShapeProperty>(ref segmentReader, formatterResolver);
8383
case FieldType.Shape: return Deserialize<ShapeProperty>(ref segmentReader, formatterResolver);
84+
case FieldType.Point: return Deserialize<PointProperty>(ref segmentReader, formatterResolver);
8485
case FieldType.Completion: return Deserialize<CompletionProperty>(ref segmentReader, formatterResolver);
8586
case FieldType.TokenCount: return Deserialize<TokenCountProperty>(ref segmentReader, formatterResolver);
8687
case FieldType.Murmur3Hash: return Deserialize<Murmur3HashProperty>(ref segmentReader, formatterResolver);
@@ -158,6 +159,9 @@ public void Serialize(ref JsonWriter writer, IProperty value, IJsonFormatterReso
158159
case IShapeProperty shapeProperty:
159160
Serialize(ref writer, shapeProperty, formatterResolver);
160161
break;
162+
case IPointProperty pointProperty:
163+
Serialize(ref writer, pointProperty, formatterResolver);
164+
break;
161165
case ICompletionProperty completionProperty:
162166
Serialize(ref writer, completionProperty, formatterResolver);
163167
break;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace Nest
6+
{
7+
/// <inheritdoc cref="IPointProperty" />
8+
public class PointAttribute : ElasticsearchPropertyAttributeBase, IPointProperty
9+
{
10+
public PointAttribute() : base(FieldType.Point) { }
11+
12+
bool? IPointProperty.IgnoreMalformed { get; set; }
13+
bool? IPointProperty.IgnoreZValue { get; set; }
14+
CartesianPoint IPointProperty.NullValue { get; set; }
15+
16+
private IPointProperty Self => this;
17+
18+
/// <inheritdoc cref="IPointProperty.IgnoreMalformed" />
19+
public bool IgnoreMalformed
20+
{
21+
get => Self.IgnoreMalformed.GetValueOrDefault(false);
22+
set => Self.IgnoreMalformed = value;
23+
}
24+
25+
/// <inheritdoc cref="IPointProperty.IgnoreZValue" />
26+
public bool IgnoreZValue
27+
{
28+
get => Self.IgnoreZValue.GetValueOrDefault(true);
29+
set => Self.IgnoreZValue = value;
30+
}
31+
32+
/// <inheritdoc cref="IPointProperty.NullValue" />
33+
public CartesianPoint NullValue
34+
{
35+
get => Self.NullValue;
36+
set => Self.NullValue = value;
37+
}
38+
}
39+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.Diagnostics;
6+
using System.Runtime.Serialization;
7+
using Elasticsearch.Net.Utf8Json;
8+
9+
namespace Nest
10+
{
11+
/// <summary>
12+
/// The point datatype facilitates the indexing of and searching
13+
/// arbitrary `x, y` pairs that fall in a 2-dimensional planar
14+
/// coordinate system.
15+
/// <para />
16+
/// You can query documents using this type using <see cref="IShapeQuery"/>.
17+
/// <para />
18+
/// Available in Elasticsearch 7.8.0+ with at least basic license level
19+
/// </summary>
20+
[InterfaceDataContract]
21+
public interface IPointProperty : IProperty
22+
{
23+
/// <summary>
24+
/// If <c>true</c>, malformed geojson shapes are ignored. If false (default),
25+
/// malformed geojson shapes throw an exception and reject the whole document.
26+
/// </summary>
27+
[DataMember(Name ="ignore_malformed")]
28+
bool? IgnoreMalformed { get; set; }
29+
30+
/// <summary>
31+
/// If true (default) three dimension points will be accepted (stored in source) but
32+
/// only x and y values will be indexed; the third dimension is ignored. If false,
33+
/// geo-points containing any more than x and y (two dimensions) values throw
34+
/// an exception and reject the whole document.
35+
/// </summary>
36+
[DataMember(Name ="ignore_z_value")]
37+
bool? IgnoreZValue { get; set; }
38+
39+
/// <summary>
40+
/// Accepts an point value which is substituted for any explicit `null` values.
41+
/// Defaults to `null`, which means the field is treated as missing.
42+
/// </summary>
43+
[DataMember(Name = "null_value")]
44+
CartesianPoint NullValue { get; set; }
45+
}
46+
47+
/// <inheritdoc cref="IPointProperty" />
48+
[DebuggerDisplay("{DebugDisplay}")]
49+
public class PointProperty : PropertyBase, IPointProperty
50+
{
51+
public PointProperty() : base(FieldType.Point) { }
52+
53+
/// <inheritdoc />
54+
public bool? IgnoreMalformed { get; set; }
55+
56+
/// <inheritdoc />
57+
public bool? IgnoreZValue { get; set; }
58+
59+
/// <inheritdoc />
60+
public CartesianPoint NullValue { get; set; }
61+
}
62+
63+
/// <inheritdoc cref="IPointProperty" />
64+
[DebuggerDisplay("{DebugDisplay}")]
65+
public class PointPropertyDescriptor<T>
66+
: PropertyDescriptorBase<PointPropertyDescriptor<T>, IPointProperty, T>, IPointProperty
67+
where T : class
68+
{
69+
public PointPropertyDescriptor() : base(FieldType.Point) { }
70+
71+
bool? IPointProperty.IgnoreMalformed { get; set; }
72+
bool? IPointProperty.IgnoreZValue { get; set; }
73+
CartesianPoint IPointProperty.NullValue { get; set; }
74+
75+
/// <inheritdoc cref="IPointProperty.IgnoreMalformed" />
76+
public PointPropertyDescriptor<T> IgnoreMalformed(bool? ignoreMalformed = true) =>
77+
Assign(ignoreMalformed, (a, v) => a.IgnoreMalformed = v);
78+
79+
/// <inheritdoc cref="IPointProperty.IgnoreZValue" />
80+
public PointPropertyDescriptor<T> IgnoreZValue(bool? ignoreZValue = true) =>
81+
Assign(ignoreZValue, (a, v) => a.IgnoreZValue = v);
82+
83+
/// <inheritdoc cref="IPointProperty.NullValue" />
84+
public PointPropertyDescriptor<T> NullValue(CartesianPoint nullValue) =>
85+
Assign(nullValue, (a, v) => a.NullValue = v);
86+
}
87+
}

0 commit comments

Comments
 (0)