Skip to content

Commit 5f6a56d

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 39bdac2 commit 5f6a56d

File tree

17 files changed

+543
-3
lines changed

17 files changed

+543
-3
lines changed

src/Nest/Mapping/DynamicTemplate/SingleMapping.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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/FieldType.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,8 @@ public enum FieldType
152152

153153
[EnumMember(Value = "wildcard")]
154154
Wildcard,
155+
156+
[EnumMember(Value = "point")]
157+
Point,
155158
}
156159
}

src/Nest/Mapping/Types/Properties.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

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

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

162+
/// <inheritdoc cref="IBinaryProperty"/>
159163
public PropertiesDescriptor<T> Binary(Func<BinaryPropertyDescriptor<T>, IBinaryProperty> selector) => SetProperty(selector);
160164

165+
/// <inheritdoc cref="IBooleanProperty"/>
161166
public PropertiesDescriptor<T> Boolean(Func<BooleanPropertyDescriptor<T>, IBooleanProperty> selector) => SetProperty(selector);
162167

168+
/// <inheritdoc cref="ICompletionProperty"/>
163169
public PropertiesDescriptor<T> Completion(Func<CompletionPropertyDescriptor<T>, ICompletionProperty> selector) => SetProperty(selector);
164170

171+
/// <inheritdoc cref="IDateProperty"/>
165172
public PropertiesDescriptor<T> Date(Func<DatePropertyDescriptor<T>, IDateProperty> selector) => SetProperty(selector);
166173

174+
/// <inheritdoc cref="IDateNanosProperty"/>
167175
public PropertiesDescriptor<T> DateNanos(Func<DateNanosPropertyDescriptor<T>, IDateNanosProperty> selector) => SetProperty(selector);
168176

177+
/// <inheritdoc cref="IDateRangeProperty"/>
169178
public PropertiesDescriptor<T> DateRange(Func<DateRangePropertyDescriptor<T>, IDateRangeProperty> selector) => SetProperty(selector);
170179

180+
/// <inheritdoc cref="IDoubleRangeProperty"/>
171181
public PropertiesDescriptor<T> DoubleRange(Func<DoubleRangePropertyDescriptor<T>, IDoubleRangeProperty> selector) => SetProperty(selector);
172182

183+
/// <inheritdoc cref="IFloatRangeProperty"/>
173184
public PropertiesDescriptor<T> FloatRange(Func<FloatRangePropertyDescriptor<T>, IFloatRangeProperty> selector) => SetProperty(selector);
174185

186+
/// <inheritdoc cref="IGeoPointProperty"/>
175187
public PropertiesDescriptor<T> GeoPoint(Func<GeoPointPropertyDescriptor<T>, IGeoPointProperty> selector) => SetProperty(selector);
176188

189+
/// <inheritdoc cref="IGeoShapeProperty"/>
177190
public PropertiesDescriptor<T> GeoShape(Func<GeoShapePropertyDescriptor<T>, IGeoShapeProperty> selector) => SetProperty(selector);
178191

192+
/// <inheritdoc cref="IShapeProperty"/>
179193
public PropertiesDescriptor<T> Shape(Func<ShapePropertyDescriptor<T>, IShapeProperty> selector) => SetProperty(selector);
180194

195+
/// <inheritdoc cref="IPointProperty"/>
196+
public PropertiesDescriptor<T> Point(Func<PointPropertyDescriptor<T>, IPointProperty> selector) => SetProperty(selector);
197+
198+
/// <inheritdoc cref="IIntegerRangeProperty"/>
181199
public PropertiesDescriptor<T> IntegerRange(Func<IntegerRangePropertyDescriptor<T>, IIntegerRangeProperty> selector) => SetProperty(selector);
182200

201+
/// <inheritdoc cref="IIpProperty"/>
183202
public PropertiesDescriptor<T> Ip(Func<IpPropertyDescriptor<T>, IIpProperty> selector) => SetProperty(selector);
184203

204+
/// <inheritdoc cref="IIpRangeProperty"/>
185205
public PropertiesDescriptor<T> IpRange(Func<IpRangePropertyDescriptor<T>, IIpRangeProperty> selector) => SetProperty(selector);
186206

207+
/// <inheritdoc cref="IJoinProperty"/>
187208
public PropertiesDescriptor<T> Join(Func<JoinPropertyDescriptor<T>, IJoinProperty> selector) => SetProperty(selector);
188209

210+
/// <inheritdoc cref="IKeywordProperty"/>
189211
public PropertiesDescriptor<T> Keyword(Func<KeywordPropertyDescriptor<T>, IKeywordProperty> selector) => SetProperty(selector);
190212

213+
/// <inheritdoc cref="ILongRangeProperty"/>
191214
public PropertiesDescriptor<T> LongRange(Func<LongRangePropertyDescriptor<T>, ILongRangeProperty> selector) => SetProperty(selector);
192215

216+
/// <inheritdoc cref="IMurmur3HashProperty"/>
193217
public PropertiesDescriptor<T> Murmur3Hash(Func<Murmur3HashPropertyDescriptor<T>, IMurmur3HashProperty> selector) => SetProperty(selector);
194218

219+
/// <inheritdoc cref="INestedProperty"/>
195220
public PropertiesDescriptor<T> Nested<TChild>(Func<NestedPropertyDescriptor<T, TChild>, INestedProperty> selector)
196221
where TChild : class => SetProperty(selector);
197222

@@ -202,18 +227,23 @@ public PropertiesDescriptor<T> Nested<TChild>(Func<NestedPropertyDescriptor<T, T
202227
/// </summary>
203228
public PropertiesDescriptor<T> Number(Func<NumberPropertyDescriptor<T>, INumberProperty> selector) => SetProperty(selector);
204229

230+
/// <inheritdoc cref="IObjectProperty"/>
205231
public PropertiesDescriptor<T> Object<TChild>(Func<ObjectTypeDescriptor<T, TChild>, IObjectProperty> selector)
206232
where TChild : class => SetProperty(selector);
207233

234+
/// <inheritdoc cref="IPercolatorProperty"/>
208235
public PropertiesDescriptor<T> Percolator(Func<PercolatorPropertyDescriptor<T>, IPercolatorProperty> selector) => SetProperty(selector);
209236

237+
/// <inheritdoc cref="ITextProperty"/>
210238
public PropertiesDescriptor<T> Text(Func<TextPropertyDescriptor<T>, ITextProperty> selector) => SetProperty(selector);
211239

212240
/// <inheritdoc cref="ISearchAsYouTypeProperty"/>
213241
public PropertiesDescriptor<T> SearchAsYouType(Func<SearchAsYouTypePropertyDescriptor<T>, ISearchAsYouTypeProperty> selector) => SetProperty(selector);
214242

243+
/// <inheritdoc cref="ITokenCountProperty"/>
215244
public PropertiesDescriptor<T> TokenCount(Func<TokenCountPropertyDescriptor<T>, ITokenCountProperty> selector) => SetProperty(selector);
216245

246+
/// <inheritdoc cref="IFieldAliasProperty"/>
217247
public PropertiesDescriptor<T> FieldAlias(Func<FieldAliasPropertyDescriptor<T>, IFieldAliasProperty> selector) => SetProperty(selector);
218248

219249
/// <inheritdoc cref="IRankFeatureProperty"/>
@@ -236,6 +266,9 @@ public PropertiesDescriptor<T> ConstantKeyword(Func<ConstantKeywordPropertyDescr
236266
public PropertiesDescriptor<T> Wildcard(Func<WildcardPropertyDescriptor<T>, IWildcardProperty> selector) =>
237267
SetProperty(selector);
238268

269+
/// <summary>
270+
/// Map a custom property.
271+
/// </summary>
239272
public PropertiesDescriptor<T> Custom(IProperty customType) => SetProperty(customType);
240273

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

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);
@@ -159,6 +160,9 @@ public void Serialize(ref JsonWriter writer, IProperty value, IJsonFormatterReso
159160
case IShapeProperty shapeProperty:
160161
Serialize(ref writer, shapeProperty, formatterResolver);
161162
break;
163+
case IPointProperty pointProperty:
164+
Serialize(ref writer, pointProperty, formatterResolver);
165+
break;
162166
case ICompletionProperty completionProperty:
163167
Serialize(ref writer, completionProperty, formatterResolver);
164168
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+
}

src/Nest/Mapping/Visitor/IMappingVisitor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public interface IMappingVisitor
3434

3535
void Visit(IShapeProperty property);
3636

37+
void Visit(IPointProperty property);
38+
3739
void Visit(INumberProperty property);
3840

3941
void Visit(ICompletionProperty property);
@@ -89,6 +91,8 @@ public virtual void Visit(IBooleanProperty property) { }
8991

9092
public virtual void Visit(IBinaryProperty property) { }
9193

94+
public virtual void Visit(IPointProperty property) { }
95+
9296
public virtual void Visit(INumberProperty property) { }
9397

9498
public virtual void Visit(IObjectProperty property) { }

src/Nest/Mapping/Visitor/IPropertyVisitor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public interface IPropertyVisitor
3232

3333
void Visit(IShapeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
3434

35+
void Visit(IPointProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
36+
3537
void Visit(ICompletionProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
3638

3739
void Visit(IIpProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);

src/Nest/Mapping/Visitor/MappingWalker.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ public void Accept(IProperties properties)
165165
Accept(t.Fields);
166166
});
167167
break;
168+
case FieldType.Point:
169+
Visit<IPointProperty>(field, t =>
170+
{
171+
_visitor.Visit(t);
172+
});
173+
break;
168174
case FieldType.Completion:
169175
Visit<ICompletionProperty>(field, t =>
170176
{

src/Nest/Mapping/Visitor/NoopPropertyVisitor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public virtual void Visit(IGeoShapeProperty type, PropertyInfo propertyInfo, Ela
2121

2222
public virtual void Visit(IShapeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute) { }
2323

24+
public virtual void Visit(IPointProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute) { }
25+
2426
public virtual void Visit(ICompletionProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute) { }
2527

2628
public virtual void Visit(IMurmur3HashProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute) { }

0 commit comments

Comments
 (0)