diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/CoordsGeoBounds.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/CoordsGeoBounds.g.cs index 417dad1a4be..93802e38cee 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/CoordsGeoBounds.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/CoordsGeoBounds.g.cs @@ -28,18 +28,72 @@ public partial class CoordsGeoBounds { [JsonInclude] [JsonPropertyName("bottom")] - public double Bottom { get; init; } + public double Bottom { get; set; } [JsonInclude] [JsonPropertyName("left")] - public double Left { get; init; } + public double Left { get; set; } [JsonInclude] [JsonPropertyName("right")] - public double Right { get; init; } + public double Right { get; set; } [JsonInclude] [JsonPropertyName("top")] - public double Top { get; init; } + public double Top { get; set; } + } + + public sealed partial class CoordsGeoBoundsDescriptor : SerializableDescriptorBase + { + internal CoordsGeoBoundsDescriptor(Action configure) => configure.Invoke(this); + public CoordsGeoBoundsDescriptor() : base() + { + } + + private double BottomValue { get; set; } + + private double LeftValue { get; set; } + + private double RightValue { get; set; } + + private double TopValue { get; set; } + + public CoordsGeoBoundsDescriptor Bottom(double bottom) + { + BottomValue = bottom; + return Self; + } + + public CoordsGeoBoundsDescriptor Left(double left) + { + LeftValue = left; + return Self; + } + + public CoordsGeoBoundsDescriptor Right(double right) + { + RightValue = right; + return Self; + } + + public CoordsGeoBoundsDescriptor Top(double top) + { + TopValue = top; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("bottom"); + writer.WriteNumberValue(BottomValue); + writer.WritePropertyName("left"); + writer.WriteNumberValue(LeftValue); + writer.WritePropertyName("right"); + writer.WriteNumberValue(RightValue); + writer.WritePropertyName("top"); + writer.WriteNumberValue(TopValue); + writer.WriteEndObject(); + } } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/GeoDistanceSort.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/GeoDistanceSort.g.cs index 7258c9414c4..8977f6e7d13 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/GeoDistanceSort.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/GeoDistanceSort.g.cs @@ -24,16 +24,126 @@ #nullable restore namespace Elastic.Clients.Elasticsearch { + internal sealed class GeoDistanceSortConverter : JsonConverter + { + public override GeoDistanceSort Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new GeoDistanceSort(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "distance_type") + { + variant.DistanceType = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "ignore_unmapped") + { + variant.IgnoreUnmapped = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "mode") + { + variant.Mode = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "order") + { + variant.Order = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "unit") + { + variant.Unit = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + variant.Field = property; + reader.Read(); + variant.Location = JsonSerializer.Deserialize>(ref reader, options); + } + } + + reader.Read(); + return variant; + } + + public override void Write(Utf8JsonWriter writer, GeoDistanceSort value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (value.Field is not null && value.Location is not null) + { + if (!options.TryGetClientSettings(out var settings)) + { + throw new JsonException("Unable to retrive client settings for JsonSerializerOptions."); + } + + var propertyName = settings.Inferrer.Field(value.Field); + writer.WritePropertyName(propertyName); + JsonSerializer.Serialize(writer, value.Location, options); + } + + if (value.DistanceType is not null) + { + writer.WritePropertyName("distance_type"); + JsonSerializer.Serialize(writer, value.DistanceType, options); + } + + if (value.IgnoreUnmapped.HasValue) + { + writer.WritePropertyName("ignore_unmapped"); + writer.WriteBooleanValue(value.IgnoreUnmapped.Value); + } + + if (value.Mode is not null) + { + writer.WritePropertyName("mode"); + JsonSerializer.Serialize(writer, value.Mode, options); + } + + if (value.Order is not null) + { + writer.WritePropertyName("order"); + JsonSerializer.Serialize(writer, value.Order, options); + } + + if (value.Unit is not null) + { + writer.WritePropertyName("unit"); + JsonSerializer.Serialize(writer, value.Unit, options); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(GeoDistanceSortConverter))] public partial class GeoDistanceSort : ISortOptionsVariant { [JsonInclude] [JsonPropertyName("distance_type")] public Elastic.Clients.Elasticsearch.GeoDistanceType? DistanceType { get; set; } + [JsonInclude] + [JsonPropertyName("field")] + public Elastic.Clients.Elasticsearch.Field Field { get; set; } + [JsonInclude] [JsonPropertyName("ignore_unmapped")] public bool? IgnoreUnmapped { get; set; } + [JsonInclude] + [JsonPropertyName("location")] + public IEnumerable Location { get; set; } + [JsonInclude] [JsonPropertyName("mode")] public Elastic.Clients.Elasticsearch.SortMode? Mode { get; set; } @@ -64,6 +174,10 @@ public GeoDistanceSortDescriptor() : base() private Elastic.Clients.Elasticsearch.DistanceUnit? UnitValue { get; set; } + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + private IEnumerable LocationValue { get; set; } + public GeoDistanceSortDescriptor DistanceType(Elastic.Clients.Elasticsearch.GeoDistanceType? distanceType) { DistanceTypeValue = distanceType; @@ -94,9 +208,34 @@ public GeoDistanceSortDescriptor Unit(Elastic.Clients.Elasticsearch.D return Self; } + public GeoDistanceSortDescriptor Location(IEnumerable location) + { + LocationValue = location; + return Self; + } + + public GeoDistanceSortDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public GeoDistanceSortDescriptor 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 (DistanceTypeValue is not null) { writer.WritePropertyName("distance_type"); @@ -148,6 +287,10 @@ public GeoDistanceSortDescriptor() : base() private Elastic.Clients.Elasticsearch.DistanceUnit? UnitValue { get; set; } + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + private IEnumerable LocationValue { get; set; } + public GeoDistanceSortDescriptor DistanceType(Elastic.Clients.Elasticsearch.GeoDistanceType? distanceType) { DistanceTypeValue = distanceType; @@ -178,9 +321,40 @@ public GeoDistanceSortDescriptor Unit(Elastic.Clients.Elasticsearch.DistanceUnit return Self; } + public GeoDistanceSortDescriptor Location(IEnumerable location) + { + LocationValue = location; + return Self; + } + + public GeoDistanceSortDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public GeoDistanceSortDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + public GeoDistanceSortDescriptor 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 (DistanceTypeValue is not null) { writer.WritePropertyName("distance_type"); diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/FieldLookup.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/FieldLookup.g.cs index 678a908a349..49046c0aa2b 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/FieldLookup.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/FieldLookup.g.cs @@ -28,18 +28,168 @@ public partial class FieldLookup { [JsonInclude] [JsonPropertyName("id")] - public string Id { get; init; } + public Elastic.Clients.Elasticsearch.Id Id { get; set; } [JsonInclude] [JsonPropertyName("index")] - public string? Index { get; init; } + public Elastic.Clients.Elasticsearch.IndexName? Index { get; set; } [JsonInclude] [JsonPropertyName("path")] - public string? Path { get; init; } + public Elastic.Clients.Elasticsearch.Field? Path { get; set; } [JsonInclude] [JsonPropertyName("routing")] - public string? Routing { get; init; } + public Elastic.Clients.Elasticsearch.Routing? Routing { get; set; } + } + + public sealed partial class FieldLookupDescriptor : SerializableDescriptorBase> + { + internal FieldLookupDescriptor(Action> configure) => configure.Invoke(this); + public FieldLookupDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.Id IdValue { get; set; } + + private Elastic.Clients.Elasticsearch.IndexName? IndexValue { get; set; } + + private Elastic.Clients.Elasticsearch.Field? PathValue { get; set; } + + private Elastic.Clients.Elasticsearch.Routing? RoutingValue { get; set; } + + public FieldLookupDescriptor Id(Elastic.Clients.Elasticsearch.Id id) + { + IdValue = id; + return Self; + } + + public FieldLookupDescriptor Index(Elastic.Clients.Elasticsearch.IndexName? index) + { + IndexValue = index; + return Self; + } + + public FieldLookupDescriptor Path(Elastic.Clients.Elasticsearch.Field? path) + { + PathValue = path; + return Self; + } + + public FieldLookupDescriptor Path(Expression> path) + { + PathValue = path; + return Self; + } + + public FieldLookupDescriptor Routing(Elastic.Clients.Elasticsearch.Routing? routing) + { + RoutingValue = routing; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("id"); + JsonSerializer.Serialize(writer, IdValue, options); + if (IndexValue is not null) + { + writer.WritePropertyName("index"); + JsonSerializer.Serialize(writer, IndexValue, options); + } + + if (PathValue is not null) + { + writer.WritePropertyName("path"); + JsonSerializer.Serialize(writer, PathValue, options); + } + + if (RoutingValue is not null) + { + writer.WritePropertyName("routing"); + JsonSerializer.Serialize(writer, RoutingValue, options); + } + + writer.WriteEndObject(); + } + } + + public sealed partial class FieldLookupDescriptor : SerializableDescriptorBase + { + internal FieldLookupDescriptor(Action configure) => configure.Invoke(this); + public FieldLookupDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.Id IdValue { get; set; } + + private Elastic.Clients.Elasticsearch.IndexName? IndexValue { get; set; } + + private Elastic.Clients.Elasticsearch.Field? PathValue { get; set; } + + private Elastic.Clients.Elasticsearch.Routing? RoutingValue { get; set; } + + public FieldLookupDescriptor Id(Elastic.Clients.Elasticsearch.Id id) + { + IdValue = id; + return Self; + } + + public FieldLookupDescriptor Index(Elastic.Clients.Elasticsearch.IndexName? index) + { + IndexValue = index; + return Self; + } + + public FieldLookupDescriptor Path(Elastic.Clients.Elasticsearch.Field? path) + { + PathValue = path; + return Self; + } + + public FieldLookupDescriptor Path(Expression> path) + { + PathValue = path; + return Self; + } + + public FieldLookupDescriptor Path(Expression> path) + { + PathValue = path; + return Self; + } + + public FieldLookupDescriptor Routing(Elastic.Clients.Elasticsearch.Routing? routing) + { + RoutingValue = routing; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("id"); + JsonSerializer.Serialize(writer, IdValue, options); + if (IndexValue is not null) + { + writer.WritePropertyName("index"); + JsonSerializer.Serialize(writer, IndexValue, options); + } + + if (PathValue is not null) + { + writer.WritePropertyName("path"); + JsonSerializer.Serialize(writer, PathValue, options); + } + + if (RoutingValue is not null) + { + writer.WritePropertyName("routing"); + JsonSerializer.Serialize(writer, RoutingValue, options); + } + + writer.WriteEndObject(); + } } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoBoundingBoxQuery.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoBoundingBoxQuery.g.cs index d676dea8e88..4ff20e065e5 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoBoundingBoxQuery.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoBoundingBoxQuery.g.cs @@ -24,8 +24,106 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.QueryDsl { + internal sealed class GeoBoundingBoxQueryConverter : JsonConverter + { + public override GeoBoundingBoxQuery Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new GeoBoundingBoxQuery(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "ignore_unmapped") + { + variant.IgnoreUnmapped = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "validation_method") + { + variant.ValidationMethod = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "_name") + { + variant.QueryName = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "boost") + { + variant.Boost = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + variant.Field = property; + reader.Read(); + variant.BoundingBox = JsonSerializer.Deserialize(ref reader, options); + } + } + + reader.Read(); + return variant; + } + + public override void Write(Utf8JsonWriter writer, GeoBoundingBoxQuery value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (value.Field is not null && value.BoundingBox is not null) + { + if (!options.TryGetClientSettings(out var settings)) + { + throw new JsonException("Unable to retrive client settings for JsonSerializerOptions."); + } + + var propertyName = settings.Inferrer.Field(value.Field); + writer.WritePropertyName(propertyName); + JsonSerializer.Serialize(writer, value.BoundingBox, options); + } + + 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); + } + + if (!string.IsNullOrEmpty(value.QueryName)) + { + writer.WritePropertyName("_name"); + writer.WriteStringValue(value.QueryName); + } + + if (value.Boost.HasValue) + { + writer.WritePropertyName("boost"); + writer.WriteNumberValue(value.Boost.Value); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(GeoBoundingBoxQueryConverter))] public partial class GeoBoundingBoxQuery : QueryBase, IQueryVariant { + [JsonInclude] + [JsonPropertyName("bounding_box")] + public Elastic.Clients.Elasticsearch.GeoBounds BoundingBox { get; set; } + + [JsonInclude] + [JsonPropertyName("field")] + public Elastic.Clients.Elasticsearch.Field Field { get; set; } + [JsonInclude] [JsonPropertyName("ignore_unmapped")] public bool? IgnoreUnmapped { get; set; } @@ -50,6 +148,10 @@ public GeoBoundingBoxQueryDescriptor() : base() private Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? ValidationMethodValue { get; set; } + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + private Elastic.Clients.Elasticsearch.GeoBounds BoundingBoxValue { get; set; } + public GeoBoundingBoxQueryDescriptor QueryName(string? queryName) { QueryNameValue = queryName; @@ -74,9 +176,34 @@ public GeoBoundingBoxQueryDescriptor ValidationMethod(Elastic.Clients return Self; } + public GeoBoundingBoxQueryDescriptor BoundingBox(Elastic.Clients.Elasticsearch.GeoBounds boundingBox) + { + BoundingBoxValue = boundingBox; + return Self; + } + + public GeoBoundingBoxQueryDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public GeoBoundingBoxQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) { writer.WriteStartObject(); + if (FieldValue is not null && BoundingBoxValue is not null) + { + var propertyName = settings.Inferrer.Field(FieldValue); + writer.WritePropertyName(propertyName); + JsonSerializer.Serialize(writer, BoundingBoxValue, options); + } + if (!string.IsNullOrEmpty(QueryNameValue)) { writer.WritePropertyName("_name"); @@ -120,6 +247,10 @@ public GeoBoundingBoxQueryDescriptor() : base() private Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? ValidationMethodValue { get; set; } + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + private Elastic.Clients.Elasticsearch.GeoBounds BoundingBoxValue { get; set; } + public GeoBoundingBoxQueryDescriptor QueryName(string? queryName) { QueryNameValue = queryName; @@ -144,9 +275,40 @@ public GeoBoundingBoxQueryDescriptor ValidationMethod(Elastic.Clients.Elasticsea return Self; } + public GeoBoundingBoxQueryDescriptor BoundingBox(Elastic.Clients.Elasticsearch.GeoBounds boundingBox) + { + BoundingBoxValue = boundingBox; + return Self; + } + + public GeoBoundingBoxQueryDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public GeoBoundingBoxQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + public GeoBoundingBoxQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) { writer.WriteStartObject(); + if (FieldValue is not null && BoundingBoxValue is not null) + { + var propertyName = settings.Inferrer.Field(FieldValue); + writer.WritePropertyName(propertyName); + JsonSerializer.Serialize(writer, BoundingBoxValue, options); + } + if (!string.IsNullOrEmpty(QueryNameValue)) { writer.WritePropertyName("_name"); diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoDistanceQuery.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoDistanceQuery.g.cs index 5d84265556b..50c86820678 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoDistanceQuery.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoDistanceQuery.g.cs @@ -24,6 +24,108 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.QueryDsl { + internal sealed 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 == "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; + } + + if (property == "_name") + { + variant.QueryName = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "boost") + { + variant.Boost = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + variant.Field = property; + reader.Read(); + variant.Location = JsonSerializer.Deserialize(ref reader, options); + } + } + + reader.Read(); + 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)) + { + throw new JsonException("Unable to retrive client settings for JsonSerializerOptions."); + } + + var propertyName = settings.Inferrer.Field(value.Field); + writer.WritePropertyName(propertyName); + JsonSerializer.Serialize(writer, value.Location, options); + } + + 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); + } + + if (!string.IsNullOrEmpty(value.QueryName)) + { + writer.WritePropertyName("_name"); + writer.WriteStringValue(value.QueryName); + } + + if (value.Boost.HasValue) + { + writer.WritePropertyName("boost"); + writer.WriteNumberValue(value.Boost.Value); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(GeoDistanceQueryConverter))] public partial class GeoDistanceQuery : QueryBase, IQueryVariant { [JsonInclude] @@ -34,6 +136,14 @@ public partial class GeoDistanceQuery : QueryBase, IQueryVariant [JsonPropertyName("distance_type")] public Elastic.Clients.Elasticsearch.GeoDistanceType? DistanceType { get; set; } + [JsonInclude] + [JsonPropertyName("field")] + public Elastic.Clients.Elasticsearch.Field Field { get; set; } + + [JsonInclude] + [JsonPropertyName("location")] + public Elastic.Clients.Elasticsearch.GeoLocation Location { get; set; } + [JsonInclude] [JsonPropertyName("validation_method")] public Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? ValidationMethod { get; set; } @@ -56,6 +166,10 @@ public GeoDistanceQueryDescriptor() : base() 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; @@ -86,9 +200,34 @@ public GeoDistanceQueryDescriptor ValidationMethod(Elastic.Clients.El 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"); @@ -140,6 +279,10 @@ public GeoDistanceQueryDescriptor() : base() 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; @@ -170,9 +313,40 @@ public GeoDistanceQueryDescriptor ValidationMethod(Elastic.Clients.Elasticsearch 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"); diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoPolygonPoints.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoPolygonPoints.g.cs index 66dcb210376..eafa7950212 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoPolygonPoints.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoPolygonPoints.g.cs @@ -28,6 +28,30 @@ public partial class GeoPolygonPoints { [JsonInclude] [JsonPropertyName("points")] - public IReadOnlyCollection Points { get; init; } + public IEnumerable Points { get; set; } + } + + public sealed partial class GeoPolygonPointsDescriptor : SerializableDescriptorBase + { + internal GeoPolygonPointsDescriptor(Action configure) => configure.Invoke(this); + public GeoPolygonPointsDescriptor() : base() + { + } + + private IEnumerable PointsValue { get; set; } + + public GeoPolygonPointsDescriptor Points(IEnumerable 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 index c4319a308e3..dc9fea7f97f 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoPolygonQuery.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoPolygonQuery.g.cs @@ -24,12 +24,110 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.QueryDsl { + internal sealed 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 == "ignore_unmapped") + { + variant.IgnoreUnmapped = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "validation_method") + { + variant.ValidationMethod = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "_name") + { + variant.QueryName = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "boost") + { + variant.Boost = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + variant.Field = property; + reader.Read(); + variant.Polygon = JsonSerializer.Deserialize(ref reader, options); + } + } + + reader.Read(); + 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)) + { + throw new JsonException("Unable to retrive client settings for JsonSerializerOptions."); + } + + var propertyName = settings.Inferrer.Field(value.Field); + writer.WritePropertyName(propertyName); + JsonSerializer.Serialize(writer, value.Polygon, options); + } + + 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); + } + + if (!string.IsNullOrEmpty(value.QueryName)) + { + writer.WritePropertyName("_name"); + writer.WriteStringValue(value.QueryName); + } + + if (value.Boost.HasValue) + { + writer.WritePropertyName("boost"); + writer.WriteNumberValue(value.Boost.Value); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(GeoPolygonQueryConverter))] public partial class GeoPolygonQuery : QueryBase, IQueryVariant { + [JsonInclude] + [JsonPropertyName("field")] + public Elastic.Clients.Elasticsearch.Field Field { get; set; } + [JsonInclude] [JsonPropertyName("ignore_unmapped")] public bool? IgnoreUnmapped { get; set; } + [JsonInclude] + [JsonPropertyName("polygon")] + public Elastic.Clients.Elasticsearch.QueryDsl.GeoPolygonPoints Polygon { get; set; } + [JsonInclude] [JsonPropertyName("validation_method")] public Elastic.Clients.Elasticsearch.QueryDsl.GeoValidationMethod? ValidationMethod { get; set; } @@ -50,6 +148,14 @@ public GeoPolygonQueryDescriptor() : base() 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; @@ -74,9 +180,62 @@ public GeoPolygonQueryDescriptor ValidationMethod(Elastic.Clients.Ela 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"); @@ -120,6 +279,14 @@ public GeoPolygonQueryDescriptor() : base() 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; @@ -144,9 +311,68 @@ public GeoPolygonQueryDescriptor ValidationMethod(Elastic.Clients.Elasticsearch. 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"); diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoShapeFieldQuery.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoShapeFieldQuery.g.cs index 0425fb8dba2..e1a59513a8f 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoShapeFieldQuery.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoShapeFieldQuery.g.cs @@ -28,14 +28,190 @@ public partial class GeoShapeFieldQuery { [JsonInclude] [JsonPropertyName("indexed_shape")] - public Elastic.Clients.Elasticsearch.QueryDsl.FieldLookup? IndexedShape { get; init; } + public Elastic.Clients.Elasticsearch.QueryDsl.FieldLookup? IndexedShape { get; set; } [JsonInclude] [JsonPropertyName("relation")] - public Elastic.Clients.Elasticsearch.GeoShapeRelation? Relation { get; init; } + public Elastic.Clients.Elasticsearch.GeoShapeRelation? Relation { get; set; } [JsonInclude] [JsonPropertyName("shape")] - public object? Shape { get; init; } + public object? Shape { get; set; } + } + + public sealed partial class GeoShapeFieldQueryDescriptor : SerializableDescriptorBase> + { + internal GeoShapeFieldQueryDescriptor(Action> configure) => configure.Invoke(this); + public GeoShapeFieldQueryDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.QueryDsl.FieldLookup? IndexedShapeValue { get; set; } + + private FieldLookupDescriptor IndexedShapeDescriptor { get; set; } + + private Action> IndexedShapeDescriptorAction { get; set; } + + private Elastic.Clients.Elasticsearch.GeoShapeRelation? RelationValue { get; set; } + + private object? ShapeValue { get; set; } + + public GeoShapeFieldQueryDescriptor IndexedShape(Elastic.Clients.Elasticsearch.QueryDsl.FieldLookup? indexedShape) + { + IndexedShapeDescriptor = null; + IndexedShapeDescriptorAction = null; + IndexedShapeValue = indexedShape; + return Self; + } + + public GeoShapeFieldQueryDescriptor IndexedShape(FieldLookupDescriptor descriptor) + { + IndexedShapeValue = null; + IndexedShapeDescriptorAction = null; + IndexedShapeDescriptor = descriptor; + return Self; + } + + public GeoShapeFieldQueryDescriptor IndexedShape(Action> configure) + { + IndexedShapeValue = null; + IndexedShapeDescriptor = null; + IndexedShapeDescriptorAction = configure; + return Self; + } + + public GeoShapeFieldQueryDescriptor Relation(Elastic.Clients.Elasticsearch.GeoShapeRelation? relation) + { + RelationValue = relation; + return Self; + } + + public GeoShapeFieldQueryDescriptor Shape(object? shape) + { + ShapeValue = shape; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + if (IndexedShapeDescriptor is not null) + { + writer.WritePropertyName("indexed_shape"); + JsonSerializer.Serialize(writer, IndexedShapeDescriptor, options); + } + else if (IndexedShapeDescriptorAction is not null) + { + writer.WritePropertyName("indexed_shape"); + JsonSerializer.Serialize(writer, new FieldLookupDescriptor(IndexedShapeDescriptorAction), options); + } + else if (IndexedShapeValue is not null) + { + writer.WritePropertyName("indexed_shape"); + JsonSerializer.Serialize(writer, IndexedShapeValue, options); + } + + if (RelationValue is not null) + { + writer.WritePropertyName("relation"); + JsonSerializer.Serialize(writer, RelationValue, options); + } + + if (ShapeValue is not null) + { + writer.WritePropertyName("shape"); + JsonSerializer.Serialize(writer, ShapeValue, options); + } + + writer.WriteEndObject(); + } + } + + public sealed partial class GeoShapeFieldQueryDescriptor : SerializableDescriptorBase + { + internal GeoShapeFieldQueryDescriptor(Action configure) => configure.Invoke(this); + public GeoShapeFieldQueryDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.QueryDsl.FieldLookup? IndexedShapeValue { get; set; } + + private FieldLookupDescriptor IndexedShapeDescriptor { get; set; } + + private Action IndexedShapeDescriptorAction { get; set; } + + private Elastic.Clients.Elasticsearch.GeoShapeRelation? RelationValue { get; set; } + + private object? ShapeValue { get; set; } + + public GeoShapeFieldQueryDescriptor IndexedShape(Elastic.Clients.Elasticsearch.QueryDsl.FieldLookup? indexedShape) + { + IndexedShapeDescriptor = null; + IndexedShapeDescriptorAction = null; + IndexedShapeValue = indexedShape; + return Self; + } + + public GeoShapeFieldQueryDescriptor IndexedShape(FieldLookupDescriptor descriptor) + { + IndexedShapeValue = null; + IndexedShapeDescriptorAction = null; + IndexedShapeDescriptor = descriptor; + return Self; + } + + public GeoShapeFieldQueryDescriptor IndexedShape(Action configure) + { + IndexedShapeValue = null; + IndexedShapeDescriptor = null; + IndexedShapeDescriptorAction = configure; + return Self; + } + + public GeoShapeFieldQueryDescriptor Relation(Elastic.Clients.Elasticsearch.GeoShapeRelation? relation) + { + RelationValue = relation; + return Self; + } + + public GeoShapeFieldQueryDescriptor Shape(object? shape) + { + ShapeValue = shape; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + if (IndexedShapeDescriptor is not null) + { + writer.WritePropertyName("indexed_shape"); + JsonSerializer.Serialize(writer, IndexedShapeDescriptor, options); + } + else if (IndexedShapeDescriptorAction is not null) + { + writer.WritePropertyName("indexed_shape"); + JsonSerializer.Serialize(writer, new FieldLookupDescriptor(IndexedShapeDescriptorAction), options); + } + else if (IndexedShapeValue is not null) + { + writer.WritePropertyName("indexed_shape"); + JsonSerializer.Serialize(writer, IndexedShapeValue, options); + } + + if (RelationValue is not null) + { + writer.WritePropertyName("relation"); + JsonSerializer.Serialize(writer, RelationValue, options); + } + + if (ShapeValue is not null) + { + writer.WritePropertyName("shape"); + JsonSerializer.Serialize(writer, ShapeValue, options); + } + + writer.WriteEndObject(); + } } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoShapeQuery.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoShapeQuery.g.cs index a7831cfbd63..7400d83457f 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoShapeQuery.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/GeoShapeQuery.g.cs @@ -24,11 +24,97 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.QueryDsl { + internal sealed class GeoShapeQueryConverter : JsonConverter + { + public override GeoShapeQuery Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new GeoShapeQuery(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "ignore_unmapped") + { + variant.IgnoreUnmapped = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "_name") + { + variant.QueryName = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "boost") + { + variant.Boost = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + variant.Field = property; + reader.Read(); + variant.Shape = JsonSerializer.Deserialize(ref reader, options); + } + } + + reader.Read(); + return variant; + } + + public override void Write(Utf8JsonWriter writer, GeoShapeQuery value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (value.Field is not null && value.Shape is not null) + { + if (!options.TryGetClientSettings(out var settings)) + { + throw new JsonException("Unable to retrive client settings for JsonSerializerOptions."); + } + + var propertyName = settings.Inferrer.Field(value.Field); + writer.WritePropertyName(propertyName); + JsonSerializer.Serialize(writer, value.Shape, options); + } + + if (value.IgnoreUnmapped.HasValue) + { + writer.WritePropertyName("ignore_unmapped"); + writer.WriteBooleanValue(value.IgnoreUnmapped.Value); + } + + if (!string.IsNullOrEmpty(value.QueryName)) + { + writer.WritePropertyName("_name"); + writer.WriteStringValue(value.QueryName); + } + + if (value.Boost.HasValue) + { + writer.WritePropertyName("boost"); + writer.WriteNumberValue(value.Boost.Value); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(GeoShapeQueryConverter))] public partial class GeoShapeQuery : QueryBase, IQueryVariant { + [JsonInclude] + [JsonPropertyName("field")] + public Elastic.Clients.Elasticsearch.Field Field { get; set; } + [JsonInclude] [JsonPropertyName("ignore_unmapped")] public bool? IgnoreUnmapped { get; set; } + + [JsonInclude] + [JsonPropertyName("shape")] + public Elastic.Clients.Elasticsearch.QueryDsl.GeoShapeFieldQuery Shape { get; set; } } public sealed partial class GeoShapeQueryDescriptor : SerializableDescriptorBase> @@ -44,6 +130,14 @@ public GeoShapeQueryDescriptor() : base() private bool? IgnoreUnmappedValue { get; set; } + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + private Elastic.Clients.Elasticsearch.QueryDsl.GeoShapeFieldQuery ShapeValue { get; set; } + + private GeoShapeFieldQueryDescriptor ShapeDescriptor { get; set; } + + private Action> ShapeDescriptorAction { get; set; } + public GeoShapeQueryDescriptor QueryName(string? queryName) { QueryNameValue = queryName; @@ -62,9 +156,62 @@ public GeoShapeQueryDescriptor IgnoreUnmapped(bool? ignoreUnmapped = return Self; } + public GeoShapeQueryDescriptor Shape(Elastic.Clients.Elasticsearch.QueryDsl.GeoShapeFieldQuery shape) + { + ShapeValue = shape; + return Self; + } + + public GeoShapeQueryDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public GeoShapeQueryDescriptor Shape(GeoShapeFieldQueryDescriptor descriptor) + { + ShapeValue = null; + ShapeDescriptorAction = null; + ShapeDescriptor = descriptor; + return Self; + } + + public GeoShapeQueryDescriptor Shape(Action> configure) + { + ShapeValue = null; + ShapeDescriptor = null; + ShapeDescriptorAction = configure; + return Self; + } + + public GeoShapeQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) { writer.WriteStartObject(); + if (FieldValue is not null && (ShapeValue is not null || ShapeDescriptor is not null || ShapeDescriptorAction is not null)) + { + var propertyName = settings.Inferrer.Field(FieldValue); + writer.WritePropertyName(propertyName); + if (ShapeValue is not null) + { + JsonSerializer.Serialize(writer, ShapeValue, options); + } + else if (ShapeDescriptor is not null) + { + JsonSerializer.Serialize(writer, ShapeDescriptor, options); + } + else if (ShapeDescriptorAction is not null) + { + var descriptor = new GeoShapeFieldQueryDescriptor(ShapeDescriptorAction); + JsonSerializer.Serialize(writer, descriptor, options); + } + } + if (!string.IsNullOrEmpty(QueryNameValue)) { writer.WritePropertyName("_name"); @@ -100,6 +247,14 @@ public GeoShapeQueryDescriptor() : base() private bool? IgnoreUnmappedValue { get; set; } + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + private Elastic.Clients.Elasticsearch.QueryDsl.GeoShapeFieldQuery ShapeValue { get; set; } + + private GeoShapeFieldQueryDescriptor ShapeDescriptor { get; set; } + + private Action ShapeDescriptorAction { get; set; } + public GeoShapeQueryDescriptor QueryName(string? queryName) { QueryNameValue = queryName; @@ -118,9 +273,68 @@ public GeoShapeQueryDescriptor IgnoreUnmapped(bool? ignoreUnmapped = true) return Self; } + public GeoShapeQueryDescriptor Shape(Elastic.Clients.Elasticsearch.QueryDsl.GeoShapeFieldQuery shape) + { + ShapeValue = shape; + return Self; + } + + public GeoShapeQueryDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public GeoShapeQueryDescriptor Shape(GeoShapeFieldQueryDescriptor descriptor) + { + ShapeValue = null; + ShapeDescriptorAction = null; + ShapeDescriptor = descriptor; + return Self; + } + + public GeoShapeQueryDescriptor Shape(Action configure) + { + ShapeValue = null; + ShapeDescriptor = null; + ShapeDescriptorAction = configure; + return Self; + } + + public GeoShapeQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + public GeoShapeQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) { writer.WriteStartObject(); + if (FieldValue is not null && (ShapeValue is not null || ShapeDescriptor is not null || ShapeDescriptorAction is not null)) + { + var propertyName = settings.Inferrer.Field(FieldValue); + writer.WritePropertyName(propertyName); + if (ShapeValue is not null) + { + JsonSerializer.Serialize(writer, ShapeValue, options); + } + else if (ShapeDescriptor is not null) + { + JsonSerializer.Serialize(writer, ShapeDescriptor, options); + } + else if (ShapeDescriptorAction is not null) + { + var descriptor = new GeoShapeFieldQueryDescriptor(ShapeDescriptorAction); + JsonSerializer.Serialize(writer, descriptor, options); + } + } + if (!string.IsNullOrEmpty(QueryNameValue)) { writer.WritePropertyName("_name"); diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/ShapeFieldQuery.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/ShapeFieldQuery.g.cs index dea4ba673d7..78d91707cd4 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/ShapeFieldQuery.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/ShapeFieldQuery.g.cs @@ -28,14 +28,190 @@ public partial class ShapeFieldQuery { [JsonInclude] [JsonPropertyName("indexed_shape")] - public Elastic.Clients.Elasticsearch.QueryDsl.FieldLookup? IndexedShape { get; init; } + public Elastic.Clients.Elasticsearch.QueryDsl.FieldLookup? IndexedShape { get; set; } [JsonInclude] [JsonPropertyName("relation")] - public Elastic.Clients.Elasticsearch.GeoShapeRelation? Relation { get; init; } + public Elastic.Clients.Elasticsearch.GeoShapeRelation? Relation { get; set; } [JsonInclude] [JsonPropertyName("shape")] - public object? Shape { get; init; } + public object? Shape { get; set; } + } + + public sealed partial class ShapeFieldQueryDescriptor : SerializableDescriptorBase> + { + internal ShapeFieldQueryDescriptor(Action> configure) => configure.Invoke(this); + public ShapeFieldQueryDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.QueryDsl.FieldLookup? IndexedShapeValue { get; set; } + + private FieldLookupDescriptor IndexedShapeDescriptor { get; set; } + + private Action> IndexedShapeDescriptorAction { get; set; } + + private Elastic.Clients.Elasticsearch.GeoShapeRelation? RelationValue { get; set; } + + private object? ShapeValue { get; set; } + + public ShapeFieldQueryDescriptor IndexedShape(Elastic.Clients.Elasticsearch.QueryDsl.FieldLookup? indexedShape) + { + IndexedShapeDescriptor = null; + IndexedShapeDescriptorAction = null; + IndexedShapeValue = indexedShape; + return Self; + } + + public ShapeFieldQueryDescriptor IndexedShape(FieldLookupDescriptor descriptor) + { + IndexedShapeValue = null; + IndexedShapeDescriptorAction = null; + IndexedShapeDescriptor = descriptor; + return Self; + } + + public ShapeFieldQueryDescriptor IndexedShape(Action> configure) + { + IndexedShapeValue = null; + IndexedShapeDescriptor = null; + IndexedShapeDescriptorAction = configure; + return Self; + } + + public ShapeFieldQueryDescriptor Relation(Elastic.Clients.Elasticsearch.GeoShapeRelation? relation) + { + RelationValue = relation; + return Self; + } + + public ShapeFieldQueryDescriptor Shape(object? shape) + { + ShapeValue = shape; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + if (IndexedShapeDescriptor is not null) + { + writer.WritePropertyName("indexed_shape"); + JsonSerializer.Serialize(writer, IndexedShapeDescriptor, options); + } + else if (IndexedShapeDescriptorAction is not null) + { + writer.WritePropertyName("indexed_shape"); + JsonSerializer.Serialize(writer, new FieldLookupDescriptor(IndexedShapeDescriptorAction), options); + } + else if (IndexedShapeValue is not null) + { + writer.WritePropertyName("indexed_shape"); + JsonSerializer.Serialize(writer, IndexedShapeValue, options); + } + + if (RelationValue is not null) + { + writer.WritePropertyName("relation"); + JsonSerializer.Serialize(writer, RelationValue, options); + } + + if (ShapeValue is not null) + { + writer.WritePropertyName("shape"); + JsonSerializer.Serialize(writer, ShapeValue, options); + } + + writer.WriteEndObject(); + } + } + + public sealed partial class ShapeFieldQueryDescriptor : SerializableDescriptorBase + { + internal ShapeFieldQueryDescriptor(Action configure) => configure.Invoke(this); + public ShapeFieldQueryDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.QueryDsl.FieldLookup? IndexedShapeValue { get; set; } + + private FieldLookupDescriptor IndexedShapeDescriptor { get; set; } + + private Action IndexedShapeDescriptorAction { get; set; } + + private Elastic.Clients.Elasticsearch.GeoShapeRelation? RelationValue { get; set; } + + private object? ShapeValue { get; set; } + + public ShapeFieldQueryDescriptor IndexedShape(Elastic.Clients.Elasticsearch.QueryDsl.FieldLookup? indexedShape) + { + IndexedShapeDescriptor = null; + IndexedShapeDescriptorAction = null; + IndexedShapeValue = indexedShape; + return Self; + } + + public ShapeFieldQueryDescriptor IndexedShape(FieldLookupDescriptor descriptor) + { + IndexedShapeValue = null; + IndexedShapeDescriptorAction = null; + IndexedShapeDescriptor = descriptor; + return Self; + } + + public ShapeFieldQueryDescriptor IndexedShape(Action configure) + { + IndexedShapeValue = null; + IndexedShapeDescriptor = null; + IndexedShapeDescriptorAction = configure; + return Self; + } + + public ShapeFieldQueryDescriptor Relation(Elastic.Clients.Elasticsearch.GeoShapeRelation? relation) + { + RelationValue = relation; + return Self; + } + + public ShapeFieldQueryDescriptor Shape(object? shape) + { + ShapeValue = shape; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + if (IndexedShapeDescriptor is not null) + { + writer.WritePropertyName("indexed_shape"); + JsonSerializer.Serialize(writer, IndexedShapeDescriptor, options); + } + else if (IndexedShapeDescriptorAction is not null) + { + writer.WritePropertyName("indexed_shape"); + JsonSerializer.Serialize(writer, new FieldLookupDescriptor(IndexedShapeDescriptorAction), options); + } + else if (IndexedShapeValue is not null) + { + writer.WritePropertyName("indexed_shape"); + JsonSerializer.Serialize(writer, IndexedShapeValue, options); + } + + if (RelationValue is not null) + { + writer.WritePropertyName("relation"); + JsonSerializer.Serialize(writer, RelationValue, options); + } + + if (ShapeValue is not null) + { + writer.WritePropertyName("shape"); + JsonSerializer.Serialize(writer, ShapeValue, options); + } + + writer.WriteEndObject(); + } } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/ShapeQuery.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/ShapeQuery.g.cs index 5b9385ea98e..1e32d976456 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/ShapeQuery.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/ShapeQuery.g.cs @@ -24,11 +24,97 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.QueryDsl { + internal sealed class ShapeQueryConverter : JsonConverter + { + public override ShapeQuery Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new ShapeQuery(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "ignore_unmapped") + { + variant.IgnoreUnmapped = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "_name") + { + variant.QueryName = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "boost") + { + variant.Boost = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + variant.Field = property; + reader.Read(); + variant.Shape = JsonSerializer.Deserialize(ref reader, options); + } + } + + reader.Read(); + return variant; + } + + public override void Write(Utf8JsonWriter writer, ShapeQuery value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (value.Field is not null && value.Shape is not null) + { + if (!options.TryGetClientSettings(out var settings)) + { + throw new JsonException("Unable to retrive client settings for JsonSerializerOptions."); + } + + var propertyName = settings.Inferrer.Field(value.Field); + writer.WritePropertyName(propertyName); + JsonSerializer.Serialize(writer, value.Shape, options); + } + + if (value.IgnoreUnmapped.HasValue) + { + writer.WritePropertyName("ignore_unmapped"); + writer.WriteBooleanValue(value.IgnoreUnmapped.Value); + } + + if (!string.IsNullOrEmpty(value.QueryName)) + { + writer.WritePropertyName("_name"); + writer.WriteStringValue(value.QueryName); + } + + if (value.Boost.HasValue) + { + writer.WritePropertyName("boost"); + writer.WriteNumberValue(value.Boost.Value); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(ShapeQueryConverter))] public partial class ShapeQuery : QueryBase, IQueryVariant { + [JsonInclude] + [JsonPropertyName("field")] + public Elastic.Clients.Elasticsearch.Field Field { get; set; } + [JsonInclude] [JsonPropertyName("ignore_unmapped")] public bool? IgnoreUnmapped { get; set; } + + [JsonInclude] + [JsonPropertyName("shape")] + public Elastic.Clients.Elasticsearch.QueryDsl.ShapeFieldQuery Shape { get; set; } } public sealed partial class ShapeQueryDescriptor : SerializableDescriptorBase> @@ -44,6 +130,14 @@ public ShapeQueryDescriptor() : base() private bool? IgnoreUnmappedValue { get; set; } + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + private Elastic.Clients.Elasticsearch.QueryDsl.ShapeFieldQuery ShapeValue { get; set; } + + private ShapeFieldQueryDescriptor ShapeDescriptor { get; set; } + + private Action> ShapeDescriptorAction { get; set; } + public ShapeQueryDescriptor QueryName(string? queryName) { QueryNameValue = queryName; @@ -62,9 +156,62 @@ public ShapeQueryDescriptor IgnoreUnmapped(bool? ignoreUnmapped = tru return Self; } + public ShapeQueryDescriptor Shape(Elastic.Clients.Elasticsearch.QueryDsl.ShapeFieldQuery shape) + { + ShapeValue = shape; + return Self; + } + + public ShapeQueryDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public ShapeQueryDescriptor Shape(ShapeFieldQueryDescriptor descriptor) + { + ShapeValue = null; + ShapeDescriptorAction = null; + ShapeDescriptor = descriptor; + return Self; + } + + public ShapeQueryDescriptor Shape(Action> configure) + { + ShapeValue = null; + ShapeDescriptor = null; + ShapeDescriptorAction = configure; + return Self; + } + + public ShapeQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) { writer.WriteStartObject(); + if (FieldValue is not null && (ShapeValue is not null || ShapeDescriptor is not null || ShapeDescriptorAction is not null)) + { + var propertyName = settings.Inferrer.Field(FieldValue); + writer.WritePropertyName(propertyName); + if (ShapeValue is not null) + { + JsonSerializer.Serialize(writer, ShapeValue, options); + } + else if (ShapeDescriptor is not null) + { + JsonSerializer.Serialize(writer, ShapeDescriptor, options); + } + else if (ShapeDescriptorAction is not null) + { + var descriptor = new ShapeFieldQueryDescriptor(ShapeDescriptorAction); + JsonSerializer.Serialize(writer, descriptor, options); + } + } + if (!string.IsNullOrEmpty(QueryNameValue)) { writer.WritePropertyName("_name"); @@ -100,6 +247,14 @@ public ShapeQueryDescriptor() : base() private bool? IgnoreUnmappedValue { get; set; } + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + private Elastic.Clients.Elasticsearch.QueryDsl.ShapeFieldQuery ShapeValue { get; set; } + + private ShapeFieldQueryDescriptor ShapeDescriptor { get; set; } + + private Action ShapeDescriptorAction { get; set; } + public ShapeQueryDescriptor QueryName(string? queryName) { QueryNameValue = queryName; @@ -118,9 +273,68 @@ public ShapeQueryDescriptor IgnoreUnmapped(bool? ignoreUnmapped = true) return Self; } + public ShapeQueryDescriptor Shape(Elastic.Clients.Elasticsearch.QueryDsl.ShapeFieldQuery shape) + { + ShapeValue = shape; + return Self; + } + + public ShapeQueryDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public ShapeQueryDescriptor Shape(ShapeFieldQueryDescriptor descriptor) + { + ShapeValue = null; + ShapeDescriptorAction = null; + ShapeDescriptor = descriptor; + return Self; + } + + public ShapeQueryDescriptor Shape(Action configure) + { + ShapeValue = null; + ShapeDescriptor = null; + ShapeDescriptorAction = configure; + return Self; + } + + public ShapeQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + public ShapeQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) { writer.WriteStartObject(); + if (FieldValue is not null && (ShapeValue is not null || ShapeDescriptor is not null || ShapeDescriptorAction is not null)) + { + var propertyName = settings.Inferrer.Field(FieldValue); + writer.WritePropertyName(propertyName); + if (ShapeValue is not null) + { + JsonSerializer.Serialize(writer, ShapeValue, options); + } + else if (ShapeDescriptor is not null) + { + JsonSerializer.Serialize(writer, ShapeDescriptor, options); + } + else if (ShapeDescriptorAction is not null) + { + var descriptor = new ShapeFieldQueryDescriptor(ShapeDescriptorAction); + JsonSerializer.Serialize(writer, descriptor, options); + } + } + if (!string.IsNullOrEmpty(QueryNameValue)) { writer.WritePropertyName("_name"); diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/TermsLookup.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/TermsLookup.g.cs index 1538c991236..2446c6676bb 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/TermsLookup.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/TermsLookup.g.cs @@ -28,18 +28,152 @@ public partial class TermsLookup { [JsonInclude] [JsonPropertyName("id")] - public string Id { get; init; } + public Elastic.Clients.Elasticsearch.Id Id { get; set; } [JsonInclude] [JsonPropertyName("index")] - public string Index { get; init; } + public Elastic.Clients.Elasticsearch.IndexName Index { get; set; } [JsonInclude] [JsonPropertyName("path")] - public string Path { get; init; } + public Elastic.Clients.Elasticsearch.Field Path { get; set; } [JsonInclude] [JsonPropertyName("routing")] - public string? Routing { get; init; } + public Elastic.Clients.Elasticsearch.Routing? Routing { get; set; } + } + + public sealed partial class TermsLookupDescriptor : SerializableDescriptorBase> + { + internal TermsLookupDescriptor(Action> configure) => configure.Invoke(this); + public TermsLookupDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.Id IdValue { get; set; } + + private Elastic.Clients.Elasticsearch.IndexName IndexValue { get; set; } + + private Elastic.Clients.Elasticsearch.Field PathValue { get; set; } + + private Elastic.Clients.Elasticsearch.Routing? RoutingValue { get; set; } + + public TermsLookupDescriptor Id(Elastic.Clients.Elasticsearch.Id id) + { + IdValue = id; + return Self; + } + + public TermsLookupDescriptor Index(Elastic.Clients.Elasticsearch.IndexName index) + { + IndexValue = index; + return Self; + } + + public TermsLookupDescriptor Path(Elastic.Clients.Elasticsearch.Field path) + { + PathValue = path; + return Self; + } + + public TermsLookupDescriptor Path(Expression> path) + { + PathValue = path; + return Self; + } + + public TermsLookupDescriptor Routing(Elastic.Clients.Elasticsearch.Routing? routing) + { + RoutingValue = routing; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("id"); + JsonSerializer.Serialize(writer, IdValue, options); + writer.WritePropertyName("index"); + JsonSerializer.Serialize(writer, IndexValue, options); + writer.WritePropertyName("path"); + JsonSerializer.Serialize(writer, PathValue, options); + if (RoutingValue is not null) + { + writer.WritePropertyName("routing"); + JsonSerializer.Serialize(writer, RoutingValue, options); + } + + writer.WriteEndObject(); + } + } + + public sealed partial class TermsLookupDescriptor : SerializableDescriptorBase + { + internal TermsLookupDescriptor(Action configure) => configure.Invoke(this); + public TermsLookupDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.Id IdValue { get; set; } + + private Elastic.Clients.Elasticsearch.IndexName IndexValue { get; set; } + + private Elastic.Clients.Elasticsearch.Field PathValue { get; set; } + + private Elastic.Clients.Elasticsearch.Routing? RoutingValue { get; set; } + + public TermsLookupDescriptor Id(Elastic.Clients.Elasticsearch.Id id) + { + IdValue = id; + return Self; + } + + public TermsLookupDescriptor Index(Elastic.Clients.Elasticsearch.IndexName index) + { + IndexValue = index; + return Self; + } + + public TermsLookupDescriptor Path(Elastic.Clients.Elasticsearch.Field path) + { + PathValue = path; + return Self; + } + + public TermsLookupDescriptor Path(Expression> path) + { + PathValue = path; + return Self; + } + + public TermsLookupDescriptor Path(Expression> path) + { + PathValue = path; + return Self; + } + + public TermsLookupDescriptor Routing(Elastic.Clients.Elasticsearch.Routing? routing) + { + RoutingValue = routing; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("id"); + JsonSerializer.Serialize(writer, IdValue, options); + writer.WritePropertyName("index"); + JsonSerializer.Serialize(writer, IndexValue, options); + writer.WritePropertyName("path"); + JsonSerializer.Serialize(writer, PathValue, options); + if (RoutingValue is not null) + { + writer.WritePropertyName("routing"); + JsonSerializer.Serialize(writer, RoutingValue, options); + } + + writer.WriteEndObject(); + } } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/TermsQuery.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/TermsQuery.g.cs index 747319b2097..d5048d17a7f 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/TermsQuery.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/QueryDsl/TermsQuery.g.cs @@ -24,8 +24,81 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.QueryDsl { + internal sealed class TermsQueryConverter : JsonConverter + { + public override TermsQuery Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new TermsQuery(); + 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; + } + + variant.Field = property; + reader.Read(); + variant.Terms = JsonSerializer.Deserialize(ref reader, options); + } + } + + reader.Read(); + return variant; + } + + public override void Write(Utf8JsonWriter writer, TermsQuery value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (value.Field is not null && value.Terms is not null) + { + if (!options.TryGetClientSettings(out var settings)) + { + throw new JsonException("Unable to retrive client settings for JsonSerializerOptions."); + } + + var propertyName = settings.Inferrer.Field(value.Field); + writer.WritePropertyName(propertyName); + JsonSerializer.Serialize(writer, value.Terms, 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); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(TermsQueryConverter))] public partial class TermsQuery : QueryBase, IQueryVariant { + [JsonInclude] + [JsonPropertyName("field")] + public Elastic.Clients.Elasticsearch.Field Field { get; set; } + + [JsonInclude] + [JsonPropertyName("terms")] + public Elastic.Clients.Elasticsearch.QueryDsl.TermsQueryField Terms { get; set; } } public sealed partial class TermsQueryDescriptor : SerializableDescriptorBase> @@ -39,6 +112,10 @@ public TermsQueryDescriptor() : base() private float? BoostValue { get; set; } + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + private Elastic.Clients.Elasticsearch.QueryDsl.TermsQueryField TermsValue { get; set; } + public TermsQueryDescriptor QueryName(string? queryName) { QueryNameValue = queryName; @@ -51,9 +128,34 @@ public TermsQueryDescriptor Boost(float? boost) return Self; } + public TermsQueryDescriptor Terms(Elastic.Clients.Elasticsearch.QueryDsl.TermsQueryField terms) + { + TermsValue = terms; + return Self; + } + + public TermsQueryDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public TermsQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) { writer.WriteStartObject(); + if (FieldValue is not null && TermsValue is not null) + { + var propertyName = settings.Inferrer.Field(FieldValue); + writer.WritePropertyName(propertyName); + JsonSerializer.Serialize(writer, TermsValue, options); + } + if (!string.IsNullOrEmpty(QueryNameValue)) { writer.WritePropertyName("_name"); @@ -81,6 +183,10 @@ public TermsQueryDescriptor() : base() private float? BoostValue { get; set; } + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + private Elastic.Clients.Elasticsearch.QueryDsl.TermsQueryField TermsValue { get; set; } + public TermsQueryDescriptor QueryName(string? queryName) { QueryNameValue = queryName; @@ -93,9 +199,40 @@ public TermsQueryDescriptor Boost(float? boost) return Self; } + public TermsQueryDescriptor Terms(Elastic.Clients.Elasticsearch.QueryDsl.TermsQueryField terms) + { + TermsValue = terms; + return Self; + } + + public TermsQueryDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public TermsQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + public TermsQueryDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) { writer.WriteStartObject(); + if (FieldValue is not null && TermsValue is not null) + { + var propertyName = settings.Inferrer.Field(FieldValue); + writer.WritePropertyName(propertyName); + JsonSerializer.Serialize(writer, TermsValue, options); + } + if (!string.IsNullOrEmpty(QueryNameValue)) { writer.WritePropertyName("_name"); diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/TopLeftBottomRightGeoBounds.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/TopLeftBottomRightGeoBounds.g.cs index da8b97961c3..6a8f99d8080 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/TopLeftBottomRightGeoBounds.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/TopLeftBottomRightGeoBounds.g.cs @@ -28,10 +28,44 @@ public partial class TopLeftBottomRightGeoBounds { [JsonInclude] [JsonPropertyName("bottom_right")] - public Elastic.Clients.Elasticsearch.GeoLocation BottomRight { get; init; } + public Elastic.Clients.Elasticsearch.GeoLocation BottomRight { get; set; } [JsonInclude] [JsonPropertyName("top_left")] - public Elastic.Clients.Elasticsearch.GeoLocation TopLeft { get; init; } + public Elastic.Clients.Elasticsearch.GeoLocation TopLeft { get; set; } + } + + public sealed partial class TopLeftBottomRightGeoBoundsDescriptor : SerializableDescriptorBase + { + internal TopLeftBottomRightGeoBoundsDescriptor(Action configure) => configure.Invoke(this); + public TopLeftBottomRightGeoBoundsDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.GeoLocation BottomRightValue { get; set; } + + private Elastic.Clients.Elasticsearch.GeoLocation TopLeftValue { get; set; } + + public TopLeftBottomRightGeoBoundsDescriptor BottomRight(Elastic.Clients.Elasticsearch.GeoLocation bottomRight) + { + BottomRightValue = bottomRight; + return Self; + } + + public TopLeftBottomRightGeoBoundsDescriptor TopLeft(Elastic.Clients.Elasticsearch.GeoLocation topLeft) + { + TopLeftValue = topLeft; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("bottom_right"); + JsonSerializer.Serialize(writer, BottomRightValue, options); + writer.WritePropertyName("top_left"); + JsonSerializer.Serialize(writer, TopLeftValue, options); + writer.WriteEndObject(); + } } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/TopRightBottomLeftGeoBounds.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/TopRightBottomLeftGeoBounds.g.cs index cf665466a6c..be3bfd9b374 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/TopRightBottomLeftGeoBounds.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/TopRightBottomLeftGeoBounds.g.cs @@ -28,10 +28,44 @@ public partial class TopRightBottomLeftGeoBounds { [JsonInclude] [JsonPropertyName("bottom_left")] - public Elastic.Clients.Elasticsearch.GeoLocation BottomLeft { get; init; } + public Elastic.Clients.Elasticsearch.GeoLocation BottomLeft { get; set; } [JsonInclude] [JsonPropertyName("top_right")] - public Elastic.Clients.Elasticsearch.GeoLocation TopRight { get; init; } + public Elastic.Clients.Elasticsearch.GeoLocation TopRight { get; set; } + } + + public sealed partial class TopRightBottomLeftGeoBoundsDescriptor : SerializableDescriptorBase + { + internal TopRightBottomLeftGeoBoundsDescriptor(Action configure) => configure.Invoke(this); + public TopRightBottomLeftGeoBoundsDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.GeoLocation BottomLeftValue { get; set; } + + private Elastic.Clients.Elasticsearch.GeoLocation TopRightValue { get; set; } + + public TopRightBottomLeftGeoBoundsDescriptor BottomLeft(Elastic.Clients.Elasticsearch.GeoLocation bottomLeft) + { + BottomLeftValue = bottomLeft; + return Self; + } + + public TopRightBottomLeftGeoBoundsDescriptor TopRight(Elastic.Clients.Elasticsearch.GeoLocation topRight) + { + TopRightValue = topRight; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("bottom_left"); + JsonSerializer.Serialize(writer, BottomLeftValue, options); + writer.WritePropertyName("top_right"); + JsonSerializer.Serialize(writer, TopRightValue, options); + writer.WriteEndObject(); + } } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/WktGeoBounds.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/WktGeoBounds.g.cs index a698fe14448..62443525443 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/WktGeoBounds.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/WktGeoBounds.g.cs @@ -28,6 +28,30 @@ public partial class WktGeoBounds { [JsonInclude] [JsonPropertyName("wkt")] - public string Wkt { get; init; } + public string Wkt { get; set; } + } + + public sealed partial class WktGeoBoundsDescriptor : SerializableDescriptorBase + { + internal WktGeoBoundsDescriptor(Action configure) => configure.Invoke(this); + public WktGeoBoundsDescriptor() : base() + { + } + + private string WktValue { get; set; } + + public WktGeoBoundsDescriptor Wkt(string wkt) + { + WktValue = wkt; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("wkt"); + writer.WriteStringValue(WktValue); + writer.WriteEndObject(); + } } } \ No newline at end of file diff --git a/tests/Tests/Serialization/Queries/SearchSerializationTests.cs b/tests/Tests/Serialization/Queries/SearchSerializationTests.cs index b3bacbeac28..904a833b456 100644 --- a/tests/Tests/Serialization/Queries/SearchSerializationTests.cs +++ b/tests/Tests/Serialization/Queries/SearchSerializationTests.cs @@ -25,4 +25,57 @@ public async Task Search_WithMatchQuery_SerializesInferredField_ForObjectInitial await Verifier.VerifyJson(json); } + + [U] + public async Task Search_WithTermsQuery_Serializes_ForObjectInitializer() + { + var container = QueryContainer.Terms(new TermsQuery + { + Field = Infer.Field(d => d.Description), + Terms = new TermsQueryField(new object[] { "term1", "term2" }), + Boost = 1.2f + }); + + var json = SerializeAndGetJsonString(container); + + await Verifier.VerifyJson(json); + } + + [U] + public async Task Search_WithTermsQuery_Serializes_ForDescriptor() + { + var container = new QueryContainerDescriptor(q => q. + Terms(t => t + .Boost(1.2f) + .Field(f => f.Description) + .Terms(new TermsQueryField(new object[] { "term1", "term2" })))); + + var json = SerializeAndGetJsonString(container); + + await Verifier.VerifyJson(json); + } + + [U] + public async Task Search_WithShapeQuery_Serializes_ForObjectInitializer() + { + var container = QueryContainer.Shape(new ShapeQuery + { + Field = Infer.Field(d => d.Description), + Shape = new ShapeFieldQuery + { + Relation = GeoShapeRelation.Within, + IndexedShape = new FieldLookup + { + Id = "deu", + Path = "location", + Index = "shapes" + } + }, + Boost = 1.2f + }); + + var json = SerializeAndGetJsonString(container); + + await Verifier.VerifyJson(json); + } } diff --git a/tests/Tests/_VerifySnapshots/SearchSerializationTests.Search_WithShapeQuery_Serializes_ForObjectInitializer.verified.txt b/tests/Tests/_VerifySnapshots/SearchSerializationTests.Search_WithShapeQuery_Serializes_ForObjectInitializer.verified.txt new file mode 100644 index 00000000000..f5cb9692127 --- /dev/null +++ b/tests/Tests/_VerifySnapshots/SearchSerializationTests.Search_WithShapeQuery_Serializes_ForObjectInitializer.verified.txt @@ -0,0 +1,13 @@ +{ + shape: { + boost: 1.2, + description: { + indexed_shape: { + id: deu, + index: shapes, + path: location + }, + relation: within + } + } +} \ No newline at end of file diff --git a/tests/Tests/_VerifySnapshots/SearchSerializationTests.Search_WithTermsQuery_Serializes_ForDescriptor.verified.txt b/tests/Tests/_VerifySnapshots/SearchSerializationTests.Search_WithTermsQuery_Serializes_ForDescriptor.verified.txt new file mode 100644 index 00000000000..8689c260d1c --- /dev/null +++ b/tests/Tests/_VerifySnapshots/SearchSerializationTests.Search_WithTermsQuery_Serializes_ForDescriptor.verified.txt @@ -0,0 +1,9 @@ +{ + terms: { + boost: 1.2, + description: [ + term1, + term2 + ] + } +} \ No newline at end of file diff --git a/tests/Tests/_VerifySnapshots/SearchSerializationTests.Search_WithTermsQuery_Serializes_ForObjectInitializer.verified.txt b/tests/Tests/_VerifySnapshots/SearchSerializationTests.Search_WithTermsQuery_Serializes_ForObjectInitializer.verified.txt new file mode 100644 index 00000000000..8689c260d1c --- /dev/null +++ b/tests/Tests/_VerifySnapshots/SearchSerializationTests.Search_WithTermsQuery_Serializes_ForObjectInitializer.verified.txt @@ -0,0 +1,9 @@ +{ + terms: { + boost: 1.2, + description: [ + term1, + term2 + ] + } +} \ No newline at end of file