diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoDistanceQuery.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoDistanceQuery.g.cs new file mode 100644 index 00000000000..f64804a9a4e --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoDistanceQuery.g.cs @@ -0,0 +1,378 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using Elastic.Clients.Elasticsearch.Fluent; +using Elastic.Clients.Elasticsearch.Serialization; +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text.Json; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch.QueryDsl; +internal sealed partial class GeoDistanceQueryConverter : JsonConverter +{ + public override GeoDistanceQuery Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new GeoDistanceQuery(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "_name") + { + variant.QueryName = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "boost") + { + variant.Boost = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "distance") + { + variant.Distance = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "distance_type") + { + variant.DistanceType = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "validation_method") + { + variant.ValidationMethod = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + variant.Field = property; + reader.Read(); + variant.Location = JsonSerializer.Deserialize(ref reader, options); + } + } + + return variant; + } + + public override void Write(Utf8JsonWriter writer, GeoDistanceQuery value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (value.Field is not null && value.Location is not null) + { + if (!options.TryGetClientSettings(out var settings)) + { + ThrowHelper.ThrowJsonExceptionForMissingSettings(); + } + + var propertyName = settings.Inferrer.Field(value.Field); + writer.WritePropertyName(propertyName); + JsonSerializer.Serialize(writer, value.Location, options); + } + + if (!string.IsNullOrEmpty(value.QueryName)) + { + writer.WritePropertyName("_name"); + writer.WriteStringValue(value.QueryName); + } + + if (value.Boost.HasValue) + { + writer.WritePropertyName("boost"); + writer.WriteNumberValue(value.Boost.Value); + } + + if (value.Distance is not null) + { + writer.WritePropertyName("distance"); + JsonSerializer.Serialize(writer, value.Distance, options); + } + + if (value.DistanceType is not null) + { + writer.WritePropertyName("distance_type"); + JsonSerializer.Serialize(writer, value.DistanceType, options); + } + + if (value.ValidationMethod is not null) + { + writer.WritePropertyName("validation_method"); + JsonSerializer.Serialize(writer, value.ValidationMethod, options); + } + + writer.WriteEndObject(); + } +} + +[JsonConverter(typeof(GeoDistanceQueryConverter))] +public sealed partial class GeoDistanceQuery : SearchQuery +{ + public string? QueryName { get; set; } + + public float? Boost { get; set; } + + public string? Distance { get; set; } + + public Elastic.Clients.Elasticsearch.GeoDistanceType? DistanceType { get; set; } + + public Elastic.Clients.Elasticsearch.Field Field { get; set; } + + public Elastic.Clients.Elasticsearch.GeoLocation Location { get; set; } + + public Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? ValidationMethod { get; set; } + + public static implicit operator Query(GeoDistanceQuery geoDistanceQuery) => QueryDsl.Query.GeoDistance(geoDistanceQuery); +} + +public sealed partial class GeoDistanceQueryDescriptor : SerializableDescriptor> +{ + internal GeoDistanceQueryDescriptor(Action> configure) => configure.Invoke(this); + public GeoDistanceQueryDescriptor() : base() + { + } + + private string? QueryNameValue { get; set; } + + private float? BoostValue { get; set; } + + private string? DistanceValue { get; set; } + + private Elastic.Clients.Elasticsearch.GeoDistanceType? DistanceTypeValue { get; set; } + + private Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? ValidationMethodValue { get; set; } + + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + private Elastic.Clients.Elasticsearch.GeoLocation LocationValue { get; set; } + + public GeoDistanceQueryDescriptor QueryName(string? queryName) + { + QueryNameValue = queryName; + return Self; + } + + public GeoDistanceQueryDescriptor Boost(float? boost) + { + BoostValue = boost; + return Self; + } + + public GeoDistanceQueryDescriptor Distance(string? distance) + { + DistanceValue = distance; + return Self; + } + + public GeoDistanceQueryDescriptor DistanceType(Elastic.Clients.Elasticsearch.GeoDistanceType? distanceType) + { + DistanceTypeValue = distanceType; + return Self; + } + + public GeoDistanceQueryDescriptor ValidationMethod(Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? validationMethod) + { + ValidationMethodValue = validationMethod; + return Self; + } + + public GeoDistanceQueryDescriptor Location(Elastic.Clients.Elasticsearch.GeoLocation location) + { + LocationValue = location; + return Self; + } + + public GeoDistanceQueryDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public GeoDistanceQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + if (FieldValue is not null && LocationValue is not null) + { + var propertyName = settings.Inferrer.Field(FieldValue); + writer.WritePropertyName(propertyName); + JsonSerializer.Serialize(writer, LocationValue, options); + } + + if (!string.IsNullOrEmpty(QueryNameValue)) + { + writer.WritePropertyName("_name"); + writer.WriteStringValue(QueryNameValue); + } + + if (BoostValue.HasValue) + { + writer.WritePropertyName("boost"); + writer.WriteNumberValue(BoostValue.Value); + } + + if (DistanceValue is not null) + { + writer.WritePropertyName("distance"); + JsonSerializer.Serialize(writer, DistanceValue, options); + } + + if (DistanceTypeValue is not null) + { + writer.WritePropertyName("distance_type"); + JsonSerializer.Serialize(writer, DistanceTypeValue, options); + } + + if (ValidationMethodValue is not null) + { + writer.WritePropertyName("validation_method"); + JsonSerializer.Serialize(writer, ValidationMethodValue, options); + } + + writer.WriteEndObject(); + } +} + +public sealed partial class GeoDistanceQueryDescriptor : SerializableDescriptor +{ + internal GeoDistanceQueryDescriptor(Action configure) => configure.Invoke(this); + public GeoDistanceQueryDescriptor() : base() + { + } + + private string? QueryNameValue { get; set; } + + private float? BoostValue { get; set; } + + private string? DistanceValue { get; set; } + + private Elastic.Clients.Elasticsearch.GeoDistanceType? DistanceTypeValue { get; set; } + + private Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? ValidationMethodValue { get; set; } + + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + private Elastic.Clients.Elasticsearch.GeoLocation LocationValue { get; set; } + + public GeoDistanceQueryDescriptor QueryName(string? queryName) + { + QueryNameValue = queryName; + return Self; + } + + public GeoDistanceQueryDescriptor Boost(float? boost) + { + BoostValue = boost; + return Self; + } + + public GeoDistanceQueryDescriptor Distance(string? distance) + { + DistanceValue = distance; + return Self; + } + + public GeoDistanceQueryDescriptor DistanceType(Elastic.Clients.Elasticsearch.GeoDistanceType? distanceType) + { + DistanceTypeValue = distanceType; + return Self; + } + + public GeoDistanceQueryDescriptor ValidationMethod(Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? validationMethod) + { + ValidationMethodValue = validationMethod; + return Self; + } + + public GeoDistanceQueryDescriptor Location(Elastic.Clients.Elasticsearch.GeoLocation location) + { + LocationValue = location; + return Self; + } + + public GeoDistanceQueryDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public GeoDistanceQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + public GeoDistanceQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + if (FieldValue is not null && LocationValue is not null) + { + var propertyName = settings.Inferrer.Field(FieldValue); + writer.WritePropertyName(propertyName); + JsonSerializer.Serialize(writer, LocationValue, options); + } + + if (!string.IsNullOrEmpty(QueryNameValue)) + { + writer.WritePropertyName("_name"); + writer.WriteStringValue(QueryNameValue); + } + + if (BoostValue.HasValue) + { + writer.WritePropertyName("boost"); + writer.WriteNumberValue(BoostValue.Value); + } + + if (DistanceValue is not null) + { + writer.WritePropertyName("distance"); + JsonSerializer.Serialize(writer, DistanceValue, options); + } + + if (DistanceTypeValue is not null) + { + writer.WritePropertyName("distance_type"); + JsonSerializer.Serialize(writer, DistanceTypeValue, options); + } + + if (ValidationMethodValue is not null) + { + writer.WritePropertyName("validation_method"); + JsonSerializer.Serialize(writer, ValidationMethodValue, options); + } + + writer.WriteEndObject(); + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoPolygonPoints.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoPolygonPoints.g.cs new file mode 100644 index 00000000000..8cab74340ea --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoPolygonPoints.g.cs @@ -0,0 +1,56 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using Elastic.Clients.Elasticsearch.Fluent; +using Elastic.Clients.Elasticsearch.Serialization; +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text.Json; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch.QueryDsl; +public sealed partial class GeoPolygonPoints +{ + [JsonInclude, JsonPropertyName("points")] + public ICollection Points { get; set; } +} + +public sealed partial class GeoPolygonPointsDescriptor : SerializableDescriptor +{ + internal GeoPolygonPointsDescriptor(Action configure) => configure.Invoke(this); + public GeoPolygonPointsDescriptor() : base() + { + } + + private ICollection PointsValue { get; set; } + + public GeoPolygonPointsDescriptor Points(ICollection points) + { + PointsValue = points; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("points"); + JsonSerializer.Serialize(writer, PointsValue, options); + writer.WriteEndObject(); + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoPolygonQuery.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoPolygonQuery.g.cs new file mode 100644 index 00000000000..b73eba6d2d5 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoPolygonQuery.g.cs @@ -0,0 +1,400 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using Elastic.Clients.Elasticsearch.Fluent; +using Elastic.Clients.Elasticsearch.Serialization; +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text.Json; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch.QueryDsl; +internal sealed partial class GeoPolygonQueryConverter : JsonConverter +{ + public override GeoPolygonQuery Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new GeoPolygonQuery(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "_name") + { + variant.QueryName = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "boost") + { + variant.Boost = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "ignore_unmapped") + { + variant.IgnoreUnmapped = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "validation_method") + { + variant.ValidationMethod = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + variant.Field = property; + reader.Read(); + variant.Polygon = JsonSerializer.Deserialize(ref reader, options); + } + } + + return variant; + } + + public override void Write(Utf8JsonWriter writer, GeoPolygonQuery value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (value.Field is not null && value.Polygon is not null) + { + if (!options.TryGetClientSettings(out var settings)) + { + ThrowHelper.ThrowJsonExceptionForMissingSettings(); + } + + var propertyName = settings.Inferrer.Field(value.Field); + writer.WritePropertyName(propertyName); + JsonSerializer.Serialize(writer, value.Polygon, options); + } + + if (!string.IsNullOrEmpty(value.QueryName)) + { + writer.WritePropertyName("_name"); + writer.WriteStringValue(value.QueryName); + } + + if (value.Boost.HasValue) + { + writer.WritePropertyName("boost"); + writer.WriteNumberValue(value.Boost.Value); + } + + if (value.IgnoreUnmapped.HasValue) + { + writer.WritePropertyName("ignore_unmapped"); + writer.WriteBooleanValue(value.IgnoreUnmapped.Value); + } + + if (value.ValidationMethod is not null) + { + writer.WritePropertyName("validation_method"); + JsonSerializer.Serialize(writer, value.ValidationMethod, options); + } + + writer.WriteEndObject(); + } +} + +[JsonConverter(typeof(GeoPolygonQueryConverter))] +public sealed partial class GeoPolygonQuery : SearchQuery +{ + public string? QueryName { get; set; } + + public float? Boost { get; set; } + + public Elastic.Clients.Elasticsearch.Field Field { get; set; } + + public bool? IgnoreUnmapped { get; set; } + + public Elastic.Clients.Elasticsearch.QueryDsl.GeoPolygonPoints Polygon { get; set; } + + public Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? ValidationMethod { get; set; } + + public static implicit operator Query(GeoPolygonQuery geoPolygonQuery) => QueryDsl.Query.GeoPolygon(geoPolygonQuery); +} + +public sealed partial class GeoPolygonQueryDescriptor : SerializableDescriptor> +{ + internal GeoPolygonQueryDescriptor(Action> configure) => configure.Invoke(this); + public GeoPolygonQueryDescriptor() : base() + { + } + + private string? QueryNameValue { get; set; } + + private float? BoostValue { get; set; } + + private bool? IgnoreUnmappedValue { get; set; } + + private Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? ValidationMethodValue { get; set; } + + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + private Elastic.Clients.Elasticsearch.QueryDsl.GeoPolygonPoints PolygonValue { get; set; } + + private GeoPolygonPointsDescriptor PolygonDescriptor { get; set; } + + private Action PolygonDescriptorAction { get; set; } + + public GeoPolygonQueryDescriptor QueryName(string? queryName) + { + QueryNameValue = queryName; + return Self; + } + + public GeoPolygonQueryDescriptor Boost(float? boost) + { + BoostValue = boost; + return Self; + } + + public GeoPolygonQueryDescriptor IgnoreUnmapped(bool? ignoreUnmapped = true) + { + IgnoreUnmappedValue = ignoreUnmapped; + return Self; + } + + public GeoPolygonQueryDescriptor ValidationMethod(Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? validationMethod) + { + ValidationMethodValue = validationMethod; + return Self; + } + + public GeoPolygonQueryDescriptor Polygon(Elastic.Clients.Elasticsearch.QueryDsl.GeoPolygonPoints polygon) + { + PolygonValue = polygon; + return Self; + } + + public GeoPolygonQueryDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public GeoPolygonQueryDescriptor Polygon(GeoPolygonPointsDescriptor descriptor) + { + PolygonValue = null; + PolygonDescriptorAction = null; + PolygonDescriptor = descriptor; + return Self; + } + + public GeoPolygonQueryDescriptor Polygon(Action configure) + { + PolygonValue = null; + PolygonDescriptor = null; + PolygonDescriptorAction = configure; + return Self; + } + + public GeoPolygonQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + if (FieldValue is not null && (PolygonValue is not null || PolygonDescriptor is not null || PolygonDescriptorAction is not null)) + { + var propertyName = settings.Inferrer.Field(FieldValue); + writer.WritePropertyName(propertyName); + if (PolygonValue is not null) + { + JsonSerializer.Serialize(writer, PolygonValue, options); + } + else if (PolygonDescriptor is not null) + { + JsonSerializer.Serialize(writer, PolygonDescriptor, options); + } + else if (PolygonDescriptorAction is not null) + { + var descriptor = new GeoPolygonPointsDescriptor(PolygonDescriptorAction); + JsonSerializer.Serialize(writer, descriptor, options); + } + } + + if (!string.IsNullOrEmpty(QueryNameValue)) + { + writer.WritePropertyName("_name"); + writer.WriteStringValue(QueryNameValue); + } + + if (BoostValue.HasValue) + { + writer.WritePropertyName("boost"); + writer.WriteNumberValue(BoostValue.Value); + } + + if (IgnoreUnmappedValue.HasValue) + { + writer.WritePropertyName("ignore_unmapped"); + writer.WriteBooleanValue(IgnoreUnmappedValue.Value); + } + + if (ValidationMethodValue is not null) + { + writer.WritePropertyName("validation_method"); + JsonSerializer.Serialize(writer, ValidationMethodValue, options); + } + + writer.WriteEndObject(); + } +} + +public sealed partial class GeoPolygonQueryDescriptor : SerializableDescriptor +{ + internal GeoPolygonQueryDescriptor(Action configure) => configure.Invoke(this); + public GeoPolygonQueryDescriptor() : base() + { + } + + private string? QueryNameValue { get; set; } + + private float? BoostValue { get; set; } + + private bool? IgnoreUnmappedValue { get; set; } + + private Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? ValidationMethodValue { get; set; } + + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + private Elastic.Clients.Elasticsearch.QueryDsl.GeoPolygonPoints PolygonValue { get; set; } + + private GeoPolygonPointsDescriptor PolygonDescriptor { get; set; } + + private Action PolygonDescriptorAction { get; set; } + + public GeoPolygonQueryDescriptor QueryName(string? queryName) + { + QueryNameValue = queryName; + return Self; + } + + public GeoPolygonQueryDescriptor Boost(float? boost) + { + BoostValue = boost; + return Self; + } + + public GeoPolygonQueryDescriptor IgnoreUnmapped(bool? ignoreUnmapped = true) + { + IgnoreUnmappedValue = ignoreUnmapped; + return Self; + } + + public GeoPolygonQueryDescriptor ValidationMethod(Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? validationMethod) + { + ValidationMethodValue = validationMethod; + return Self; + } + + public GeoPolygonQueryDescriptor Polygon(Elastic.Clients.Elasticsearch.QueryDsl.GeoPolygonPoints polygon) + { + PolygonValue = polygon; + return Self; + } + + public GeoPolygonQueryDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public GeoPolygonQueryDescriptor Polygon(GeoPolygonPointsDescriptor descriptor) + { + PolygonValue = null; + PolygonDescriptorAction = null; + PolygonDescriptor = descriptor; + return Self; + } + + public GeoPolygonQueryDescriptor Polygon(Action configure) + { + PolygonValue = null; + PolygonDescriptor = null; + PolygonDescriptorAction = configure; + return Self; + } + + public GeoPolygonQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + public GeoPolygonQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + if (FieldValue is not null && (PolygonValue is not null || PolygonDescriptor is not null || PolygonDescriptorAction is not null)) + { + var propertyName = settings.Inferrer.Field(FieldValue); + writer.WritePropertyName(propertyName); + if (PolygonValue is not null) + { + JsonSerializer.Serialize(writer, PolygonValue, options); + } + else if (PolygonDescriptor is not null) + { + JsonSerializer.Serialize(writer, PolygonDescriptor, options); + } + else if (PolygonDescriptorAction is not null) + { + var descriptor = new GeoPolygonPointsDescriptor(PolygonDescriptorAction); + JsonSerializer.Serialize(writer, descriptor, options); + } + } + + if (!string.IsNullOrEmpty(QueryNameValue)) + { + writer.WritePropertyName("_name"); + writer.WriteStringValue(QueryNameValue); + } + + if (BoostValue.HasValue) + { + writer.WritePropertyName("boost"); + writer.WriteNumberValue(BoostValue.Value); + } + + if (IgnoreUnmappedValue.HasValue) + { + writer.WritePropertyName("ignore_unmapped"); + writer.WriteBooleanValue(IgnoreUnmappedValue.Value); + } + + if (ValidationMethodValue is not null) + { + writer.WritePropertyName("validation_method"); + JsonSerializer.Serialize(writer, ValidationMethodValue, options); + } + + writer.WriteEndObject(); + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/Query.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/Query.g.cs index 627eada3fb0..380fd0342e9 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/Query.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/Query.g.cs @@ -54,6 +54,8 @@ internal Query(string variantName, object variant) public static Query FunctionScore(Elastic.Clients.Elasticsearch.QueryDsl.FunctionScoreQuery functionScoreQuery) => new Query("function_score", functionScoreQuery); public static Query Fuzzy(Elastic.Clients.Elasticsearch.QueryDsl.FuzzyQuery fuzzyQuery) => new Query("fuzzy", fuzzyQuery); public static Query GeoBoundingBox(Elastic.Clients.Elasticsearch.QueryDsl.GeoBoundingBoxQuery geoBoundingBoxQuery) => new Query("geo_bounding_box", geoBoundingBoxQuery); + public static Query GeoDistance(Elastic.Clients.Elasticsearch.QueryDsl.GeoDistanceQuery geoDistanceQuery) => new Query("geo_distance", geoDistanceQuery); + public static Query GeoPolygon(Elastic.Clients.Elasticsearch.QueryDsl.GeoPolygonQuery geoPolygonQuery) => new Query("geo_polygon", geoPolygonQuery); public static Query HasChild(Elastic.Clients.Elasticsearch.QueryDsl.HasChildQuery hasChildQuery) => new Query("has_child", hasChildQuery); public static Query HasParent(Elastic.Clients.Elasticsearch.QueryDsl.HasParentQuery hasParentQuery) => new Query("has_parent", hasParentQuery); public static Query Ids(Elastic.Clients.Elasticsearch.QueryDsl.IdsQuery idsQuery) => new Query("ids", idsQuery); @@ -180,6 +182,20 @@ public override Query Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSe return new Query(propertyName, variant); } + if (propertyName == "geo_distance") + { + var variant = JsonSerializer.Deserialize(ref reader, options); + reader.Read(); + return new Query(propertyName, variant); + } + + if (propertyName == "geo_polygon") + { + var variant = JsonSerializer.Deserialize(ref reader, options); + reader.Read(); + return new Query(propertyName, variant); + } + if (propertyName == "has_child") { var variant = JsonSerializer.Deserialize(ref reader, options); @@ -484,6 +500,12 @@ public override void Write(Utf8JsonWriter writer, Query value, JsonSerializerOpt case "geo_bounding_box": JsonSerializer.Serialize(writer, (Elastic.Clients.Elasticsearch.QueryDsl.GeoBoundingBoxQuery)value.Variant, options); break; + case "geo_distance": + JsonSerializer.Serialize(writer, (Elastic.Clients.Elasticsearch.QueryDsl.GeoDistanceQuery)value.Variant, options); + break; + case "geo_polygon": + JsonSerializer.Serialize(writer, (Elastic.Clients.Elasticsearch.QueryDsl.GeoPolygonQuery)value.Variant, options); + break; case "has_child": JsonSerializer.Serialize(writer, (Elastic.Clients.Elasticsearch.QueryDsl.HasChildQuery)value.Variant, options); break; @@ -655,6 +677,10 @@ private QueryDescriptor Set(object variant, string variantName) public QueryDescriptor Fuzzy(Action> configure) => Set(configure, "fuzzy"); public QueryDescriptor GeoBoundingBox(GeoBoundingBoxQuery geoBoundingBoxQuery) => Set(geoBoundingBoxQuery, "geo_bounding_box"); public QueryDescriptor GeoBoundingBox(Action> configure) => Set(configure, "geo_bounding_box"); + public QueryDescriptor GeoDistance(GeoDistanceQuery geoDistanceQuery) => Set(geoDistanceQuery, "geo_distance"); + public QueryDescriptor GeoDistance(Action> configure) => Set(configure, "geo_distance"); + public QueryDescriptor GeoPolygon(GeoPolygonQuery geoPolygonQuery) => Set(geoPolygonQuery, "geo_polygon"); + public QueryDescriptor GeoPolygon(Action> configure) => Set(configure, "geo_polygon"); public QueryDescriptor HasChild(HasChildQuery hasChildQuery) => Set(hasChildQuery, "has_child"); public QueryDescriptor HasChild(Action> configure) => Set(configure, "has_child"); public QueryDescriptor HasParent(HasParentQuery hasParentQuery) => Set(hasParentQuery, "has_parent"); @@ -820,6 +846,12 @@ private QueryDescriptor Set(object variant, string variantName) public QueryDescriptor GeoBoundingBox(GeoBoundingBoxQuery geoBoundingBoxQuery) => Set(geoBoundingBoxQuery, "geo_bounding_box"); public QueryDescriptor GeoBoundingBox(Action configure) => Set(configure, "geo_bounding_box"); public QueryDescriptor GeoBoundingBox(Action> configure) => Set(configure, "geo_bounding_box"); + public QueryDescriptor GeoDistance(GeoDistanceQuery geoDistanceQuery) => Set(geoDistanceQuery, "geo_distance"); + public QueryDescriptor GeoDistance(Action configure) => Set(configure, "geo_distance"); + public QueryDescriptor GeoDistance(Action> configure) => Set(configure, "geo_distance"); + public QueryDescriptor GeoPolygon(GeoPolygonQuery geoPolygonQuery) => Set(geoPolygonQuery, "geo_polygon"); + public QueryDescriptor GeoPolygon(Action configure) => Set(configure, "geo_polygon"); + public QueryDescriptor GeoPolygon(Action> configure) => Set(configure, "geo_polygon"); public QueryDescriptor HasChild(HasChildQuery hasChildQuery) => Set(hasChildQuery, "has_child"); public QueryDescriptor HasChild(Action configure) => Set(configure, "has_child"); public QueryDescriptor HasChild(Action> configure) => Set(configure, "has_child"); diff --git a/tests/Tests/QueryDsl/Geo/GeoDistanceQueryUsageTests.cs b/tests/Tests/QueryDsl/Geo/GeoDistanceQueryUsageTests.cs new file mode 100644 index 00000000000..d8cdc36c03f --- /dev/null +++ b/tests/Tests/QueryDsl/Geo/GeoDistanceQueryUsageTests.cs @@ -0,0 +1,39 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using Elastic.Clients.Elasticsearch.QueryDsl; +using Tests.Core.ManagedElasticsearch.Clusters; +using Tests.Domain; +using Tests.Framework.EndpointTests.TestState; + +namespace Tests.QueryDsl.Geo; + +public class GeoDistanceQueryUsageTests : QueryDslUsageTestsBase +{ + public GeoDistanceQueryUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) + { + } + + protected override Query QueryInitializer => new GeoDistanceQuery + { + Boost = 1.1f, + QueryName = "named_query", + Field = Infer.Field(p => p.LocationPoint), + DistanceType = GeoDistanceType.Arc, + Location = GeoLocation.LatitudeLongitude(new() { Lat = 34, Lon = 34 }), + Distance = "200m", + ValidationMethod = GeoValidationMethod.IgnoreMalformed, + }; + + protected override QueryDescriptor QueryFluent(QueryDescriptor queryDescriptor) => + queryDescriptor + .GeoDistance(g => g + .Boost(1.1f) + .QueryName("named_query") + .Field(p => p.LocationPoint) + .DistanceType(GeoDistanceType.Arc) + .Location(GeoLocation.LatitudeLongitude(new() { Lat = 34, Lon = 34 })) + .Distance("200m") + .ValidationMethod(GeoValidationMethod.IgnoreMalformed)); +} diff --git a/tests/Tests/QueryDsl/Geo/GeoPolygonQueryUsageTests.cs b/tests/Tests/QueryDsl/Geo/GeoPolygonQueryUsageTests.cs new file mode 100644 index 00000000000..09ed80036c9 --- /dev/null +++ b/tests/Tests/QueryDsl/Geo/GeoPolygonQueryUsageTests.cs @@ -0,0 +1,48 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using Elastic.Clients.Elasticsearch.QueryDsl; +using Tests.Core.ManagedElasticsearch.Clusters; +using Tests.Domain; +using Tests.Framework.EndpointTests.TestState; + +namespace Tests.QueryDsl.Geo; + +public class GeoPolygonQueryUsageTests : QueryDslUsageTestsBase +{ + public GeoPolygonQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage) { } + + protected override Query QueryInitializer => new GeoPolygonQuery + { + Boost = 1.1f, + QueryName = "named_query", + ValidationMethod = GeoValidationMethod.Strict, + Polygon = new GeoPolygonPoints + { + Points = new[] + { + GeoLocation.LatitudeLongitude(new () { Lat = 45, Lon = -45 }), + GeoLocation.LatitudeLongitude(new () { Lat = -34, Lon = -34 }), + GeoLocation.LatitudeLongitude(new () { Lat = 70, Lon = -70 }) + } + }, + Field = Infer.Field(p => p.LocationPoint), + IgnoreUnmapped = true + }; + + protected override QueryDescriptor QueryFluent(QueryDescriptor queryDescriptor) => queryDescriptor + .GeoPolygon(c => c + .QueryName("named_query") + .Boost(1.1f) + .Field(p => p.LocationPoint) + .ValidationMethod(GeoValidationMethod.Strict) + .Polygon(p => p.Points(new[] + { + GeoLocation.LatitudeLongitude(new () { Lat = 45, Lon = -45 }), + GeoLocation.LatitudeLongitude(new () { Lat = -34, Lon = -34 }), + GeoLocation.LatitudeLongitude(new () { Lat = 70, Lon = -70 }) + })) + .IgnoreUnmapped(true) + ); +} diff --git a/tests/Tests/_VerifySnapshots/GeoDistanceQueryUsageTests.VerifyDescriptorJson.verified.txt b/tests/Tests/_VerifySnapshots/GeoDistanceQueryUsageTests.VerifyDescriptorJson.verified.txt new file mode 100644 index 00000000000..a0487be4455 --- /dev/null +++ b/tests/Tests/_VerifySnapshots/GeoDistanceQueryUsageTests.VerifyDescriptorJson.verified.txt @@ -0,0 +1,15 @@ +{ + query: { + geo_distance: { + boost: 1.1, + distance: 200m, + distance_type: arc, + locationPoint: { + lat: 34, + lon: 34 + }, + validation_method: ignore_malformed, + _name: named_query + } + } +} \ No newline at end of file diff --git a/tests/Tests/_VerifySnapshots/GeoDistanceQueryUsageTests.VerifyInitializerJson.verified.txt b/tests/Tests/_VerifySnapshots/GeoDistanceQueryUsageTests.VerifyInitializerJson.verified.txt new file mode 100644 index 00000000000..a0487be4455 --- /dev/null +++ b/tests/Tests/_VerifySnapshots/GeoDistanceQueryUsageTests.VerifyInitializerJson.verified.txt @@ -0,0 +1,15 @@ +{ + query: { + geo_distance: { + boost: 1.1, + distance: 200m, + distance_type: arc, + locationPoint: { + lat: 34, + lon: 34 + }, + validation_method: ignore_malformed, + _name: named_query + } + } +} \ No newline at end of file diff --git a/tests/Tests/_VerifySnapshots/GeoPolygonQueryUsageTests.VerifyDescriptorJson.verified.txt b/tests/Tests/_VerifySnapshots/GeoPolygonQueryUsageTests.VerifyDescriptorJson.verified.txt new file mode 100644 index 00000000000..093740766f3 --- /dev/null +++ b/tests/Tests/_VerifySnapshots/GeoPolygonQueryUsageTests.VerifyDescriptorJson.verified.txt @@ -0,0 +1,26 @@ +{ + query: { + geo_polygon: { + boost: 1.1, + ignore_unmapped: true, + locationPoint: { + points: [ + { + lat: 45, + lon: -45 + }, + { + lat: -34, + lon: -34 + }, + { + lat: 70, + lon: -70 + } + ] + }, + validation_method: strict, + _name: named_query + } + } +} \ No newline at end of file diff --git a/tests/Tests/_VerifySnapshots/GeoPolygonQueryUsageTests.VerifyInitializerJson.verified.txt b/tests/Tests/_VerifySnapshots/GeoPolygonQueryUsageTests.VerifyInitializerJson.verified.txt new file mode 100644 index 00000000000..093740766f3 --- /dev/null +++ b/tests/Tests/_VerifySnapshots/GeoPolygonQueryUsageTests.VerifyInitializerJson.verified.txt @@ -0,0 +1,26 @@ +{ + query: { + geo_polygon: { + boost: 1.1, + ignore_unmapped: true, + locationPoint: { + points: [ + { + lat: 45, + lon: -45 + }, + { + lat: -34, + lon: -34 + }, + { + lat: 70, + lon: -70 + } + ] + }, + validation_method: strict, + _name: named_query + } + } +} \ No newline at end of file