Skip to content

Commit ed63cd1

Browse files
stevejgordongithub-actions[bot]
authored andcommitted
Support GeoDistance and GeoPolygon queries (#7372)
1 parent ffbfc33 commit ed63cd1

10 files changed

+1035
-0
lines changed
Lines changed: 378 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,378 @@
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+
// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
6+
// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
7+
// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗
8+
// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝
9+
// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗
10+
// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
11+
// ------------------------------------------------
12+
//
13+
// This file is automatically generated.
14+
// Please do not edit these files manually.
15+
//
16+
// ------------------------------------------------
17+
18+
using Elastic.Clients.Elasticsearch.Fluent;
19+
using Elastic.Clients.Elasticsearch.Serialization;
20+
using System;
21+
using System.Collections.Generic;
22+
using System.Linq.Expressions;
23+
using System.Text.Json;
24+
using System.Text.Json.Serialization;
25+
26+
#nullable restore
27+
namespace Elastic.Clients.Elasticsearch.QueryDsl;
28+
internal sealed partial class GeoDistanceQueryConverter : JsonConverter<GeoDistanceQuery>
29+
{
30+
public override GeoDistanceQuery Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
31+
{
32+
if (reader.TokenType != JsonTokenType.StartObject)
33+
throw new JsonException("Unexpected JSON detected.");
34+
var variant = new GeoDistanceQuery();
35+
while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
36+
{
37+
if (reader.TokenType == JsonTokenType.PropertyName)
38+
{
39+
var property = reader.GetString();
40+
if (property == "_name")
41+
{
42+
variant.QueryName = JsonSerializer.Deserialize<string?>(ref reader, options);
43+
continue;
44+
}
45+
46+
if (property == "boost")
47+
{
48+
variant.Boost = JsonSerializer.Deserialize<float?>(ref reader, options);
49+
continue;
50+
}
51+
52+
if (property == "distance")
53+
{
54+
variant.Distance = JsonSerializer.Deserialize<string?>(ref reader, options);
55+
continue;
56+
}
57+
58+
if (property == "distance_type")
59+
{
60+
variant.DistanceType = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.GeoDistanceType?>(ref reader, options);
61+
continue;
62+
}
63+
64+
if (property == "validation_method")
65+
{
66+
variant.ValidationMethod = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod?>(ref reader, options);
67+
continue;
68+
}
69+
70+
variant.Field = property;
71+
reader.Read();
72+
variant.Location = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.GeoLocation>(ref reader, options);
73+
}
74+
}
75+
76+
return variant;
77+
}
78+
79+
public override void Write(Utf8JsonWriter writer, GeoDistanceQuery value, JsonSerializerOptions options)
80+
{
81+
writer.WriteStartObject();
82+
if (value.Field is not null && value.Location is not null)
83+
{
84+
if (!options.TryGetClientSettings(out var settings))
85+
{
86+
ThrowHelper.ThrowJsonExceptionForMissingSettings();
87+
}
88+
89+
var propertyName = settings.Inferrer.Field(value.Field);
90+
writer.WritePropertyName(propertyName);
91+
JsonSerializer.Serialize(writer, value.Location, options);
92+
}
93+
94+
if (!string.IsNullOrEmpty(value.QueryName))
95+
{
96+
writer.WritePropertyName("_name");
97+
writer.WriteStringValue(value.QueryName);
98+
}
99+
100+
if (value.Boost.HasValue)
101+
{
102+
writer.WritePropertyName("boost");
103+
writer.WriteNumberValue(value.Boost.Value);
104+
}
105+
106+
if (value.Distance is not null)
107+
{
108+
writer.WritePropertyName("distance");
109+
JsonSerializer.Serialize(writer, value.Distance, options);
110+
}
111+
112+
if (value.DistanceType is not null)
113+
{
114+
writer.WritePropertyName("distance_type");
115+
JsonSerializer.Serialize(writer, value.DistanceType, options);
116+
}
117+
118+
if (value.ValidationMethod is not null)
119+
{
120+
writer.WritePropertyName("validation_method");
121+
JsonSerializer.Serialize(writer, value.ValidationMethod, options);
122+
}
123+
124+
writer.WriteEndObject();
125+
}
126+
}
127+
128+
[JsonConverter(typeof(GeoDistanceQueryConverter))]
129+
public sealed partial class GeoDistanceQuery : SearchQuery
130+
{
131+
public string? QueryName { get; set; }
132+
133+
public float? Boost { get; set; }
134+
135+
public string? Distance { get; set; }
136+
137+
public Elastic.Clients.Elasticsearch.GeoDistanceType? DistanceType { get; set; }
138+
139+
public Elastic.Clients.Elasticsearch.Field Field { get; set; }
140+
141+
public Elastic.Clients.Elasticsearch.GeoLocation Location { get; set; }
142+
143+
public Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? ValidationMethod { get; set; }
144+
145+
public static implicit operator Query(GeoDistanceQuery geoDistanceQuery) => QueryDsl.Query.GeoDistance(geoDistanceQuery);
146+
}
147+
148+
public sealed partial class GeoDistanceQueryDescriptor<TDocument> : SerializableDescriptor<GeoDistanceQueryDescriptor<TDocument>>
149+
{
150+
internal GeoDistanceQueryDescriptor(Action<GeoDistanceQueryDescriptor<TDocument>> configure) => configure.Invoke(this);
151+
public GeoDistanceQueryDescriptor() : base()
152+
{
153+
}
154+
155+
private string? QueryNameValue { get; set; }
156+
157+
private float? BoostValue { get; set; }
158+
159+
private string? DistanceValue { get; set; }
160+
161+
private Elastic.Clients.Elasticsearch.GeoDistanceType? DistanceTypeValue { get; set; }
162+
163+
private Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? ValidationMethodValue { get; set; }
164+
165+
private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; }
166+
167+
private Elastic.Clients.Elasticsearch.GeoLocation LocationValue { get; set; }
168+
169+
public GeoDistanceQueryDescriptor<TDocument> QueryName(string? queryName)
170+
{
171+
QueryNameValue = queryName;
172+
return Self;
173+
}
174+
175+
public GeoDistanceQueryDescriptor<TDocument> Boost(float? boost)
176+
{
177+
BoostValue = boost;
178+
return Self;
179+
}
180+
181+
public GeoDistanceQueryDescriptor<TDocument> Distance(string? distance)
182+
{
183+
DistanceValue = distance;
184+
return Self;
185+
}
186+
187+
public GeoDistanceQueryDescriptor<TDocument> DistanceType(Elastic.Clients.Elasticsearch.GeoDistanceType? distanceType)
188+
{
189+
DistanceTypeValue = distanceType;
190+
return Self;
191+
}
192+
193+
public GeoDistanceQueryDescriptor<TDocument> ValidationMethod(Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? validationMethod)
194+
{
195+
ValidationMethodValue = validationMethod;
196+
return Self;
197+
}
198+
199+
public GeoDistanceQueryDescriptor<TDocument> Location(Elastic.Clients.Elasticsearch.GeoLocation location)
200+
{
201+
LocationValue = location;
202+
return Self;
203+
}
204+
205+
public GeoDistanceQueryDescriptor<TDocument> Field(Elastic.Clients.Elasticsearch.Field field)
206+
{
207+
FieldValue = field;
208+
return Self;
209+
}
210+
211+
public GeoDistanceQueryDescriptor<TDocument> Field<TValue>(Expression<Func<TDocument, TValue>> field)
212+
{
213+
FieldValue = field;
214+
return Self;
215+
}
216+
217+
protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
218+
{
219+
writer.WriteStartObject();
220+
if (FieldValue is not null && LocationValue is not null)
221+
{
222+
var propertyName = settings.Inferrer.Field(FieldValue);
223+
writer.WritePropertyName(propertyName);
224+
JsonSerializer.Serialize(writer, LocationValue, options);
225+
}
226+
227+
if (!string.IsNullOrEmpty(QueryNameValue))
228+
{
229+
writer.WritePropertyName("_name");
230+
writer.WriteStringValue(QueryNameValue);
231+
}
232+
233+
if (BoostValue.HasValue)
234+
{
235+
writer.WritePropertyName("boost");
236+
writer.WriteNumberValue(BoostValue.Value);
237+
}
238+
239+
if (DistanceValue is not null)
240+
{
241+
writer.WritePropertyName("distance");
242+
JsonSerializer.Serialize(writer, DistanceValue, options);
243+
}
244+
245+
if (DistanceTypeValue is not null)
246+
{
247+
writer.WritePropertyName("distance_type");
248+
JsonSerializer.Serialize(writer, DistanceTypeValue, options);
249+
}
250+
251+
if (ValidationMethodValue is not null)
252+
{
253+
writer.WritePropertyName("validation_method");
254+
JsonSerializer.Serialize(writer, ValidationMethodValue, options);
255+
}
256+
257+
writer.WriteEndObject();
258+
}
259+
}
260+
261+
public sealed partial class GeoDistanceQueryDescriptor : SerializableDescriptor<GeoDistanceQueryDescriptor>
262+
{
263+
internal GeoDistanceQueryDescriptor(Action<GeoDistanceQueryDescriptor> configure) => configure.Invoke(this);
264+
public GeoDistanceQueryDescriptor() : base()
265+
{
266+
}
267+
268+
private string? QueryNameValue { get; set; }
269+
270+
private float? BoostValue { get; set; }
271+
272+
private string? DistanceValue { get; set; }
273+
274+
private Elastic.Clients.Elasticsearch.GeoDistanceType? DistanceTypeValue { get; set; }
275+
276+
private Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? ValidationMethodValue { get; set; }
277+
278+
private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; }
279+
280+
private Elastic.Clients.Elasticsearch.GeoLocation LocationValue { get; set; }
281+
282+
public GeoDistanceQueryDescriptor QueryName(string? queryName)
283+
{
284+
QueryNameValue = queryName;
285+
return Self;
286+
}
287+
288+
public GeoDistanceQueryDescriptor Boost(float? boost)
289+
{
290+
BoostValue = boost;
291+
return Self;
292+
}
293+
294+
public GeoDistanceQueryDescriptor Distance(string? distance)
295+
{
296+
DistanceValue = distance;
297+
return Self;
298+
}
299+
300+
public GeoDistanceQueryDescriptor DistanceType(Elastic.Clients.Elasticsearch.GeoDistanceType? distanceType)
301+
{
302+
DistanceTypeValue = distanceType;
303+
return Self;
304+
}
305+
306+
public GeoDistanceQueryDescriptor ValidationMethod(Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? validationMethod)
307+
{
308+
ValidationMethodValue = validationMethod;
309+
return Self;
310+
}
311+
312+
public GeoDistanceQueryDescriptor Location(Elastic.Clients.Elasticsearch.GeoLocation location)
313+
{
314+
LocationValue = location;
315+
return Self;
316+
}
317+
318+
public GeoDistanceQueryDescriptor Field(Elastic.Clients.Elasticsearch.Field field)
319+
{
320+
FieldValue = field;
321+
return Self;
322+
}
323+
324+
public GeoDistanceQueryDescriptor Field<TDocument, TValue>(Expression<Func<TDocument, TValue>> field)
325+
{
326+
FieldValue = field;
327+
return Self;
328+
}
329+
330+
public GeoDistanceQueryDescriptor Field<TDocument>(Expression<Func<TDocument, object>> field)
331+
{
332+
FieldValue = field;
333+
return Self;
334+
}
335+
336+
protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
337+
{
338+
writer.WriteStartObject();
339+
if (FieldValue is not null && LocationValue is not null)
340+
{
341+
var propertyName = settings.Inferrer.Field(FieldValue);
342+
writer.WritePropertyName(propertyName);
343+
JsonSerializer.Serialize(writer, LocationValue, options);
344+
}
345+
346+
if (!string.IsNullOrEmpty(QueryNameValue))
347+
{
348+
writer.WritePropertyName("_name");
349+
writer.WriteStringValue(QueryNameValue);
350+
}
351+
352+
if (BoostValue.HasValue)
353+
{
354+
writer.WritePropertyName("boost");
355+
writer.WriteNumberValue(BoostValue.Value);
356+
}
357+
358+
if (DistanceValue is not null)
359+
{
360+
writer.WritePropertyName("distance");
361+
JsonSerializer.Serialize(writer, DistanceValue, options);
362+
}
363+
364+
if (DistanceTypeValue is not null)
365+
{
366+
writer.WritePropertyName("distance_type");
367+
JsonSerializer.Serialize(writer, DistanceTypeValue, options);
368+
}
369+
370+
if (ValidationMethodValue is not null)
371+
{
372+
writer.WritePropertyName("validation_method");
373+
JsonSerializer.Serialize(writer, ValidationMethodValue, options);
374+
}
375+
376+
writer.WriteEndObject();
377+
}
378+
}

0 commit comments

Comments
 (0)