diff --git a/exclusion.dic b/exclusion.dic index c62eea6303e..ec92df46717 100644 --- a/exclusion.dic +++ b/exclusion.dic @@ -6,4 +6,5 @@ asciidocs yyyy enum trippable -geotile \ No newline at end of file +geotile +yaml \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/Types/Aggregations/AggregateDictionaryConverter.cs b/src/Elastic.Clients.Elasticsearch/Types/Aggregations/AggregateDictionaryConverter.cs index 39fe015c96f..00f3e72537e 100644 --- a/src/Elastic.Clients.Elasticsearch/Types/Aggregations/AggregateDictionaryConverter.cs +++ b/src/Elastic.Clients.Elasticsearch/Types/Aggregations/AggregateDictionaryConverter.cs @@ -256,26 +256,26 @@ public static void ReadAggregate(ref Utf8JsonReader reader, JsonSerializerOption break; } - //case "geo_bounds": - // { - // var agg = JsonSerializer.Deserialize(ref reader, options); - // dictionary.Add(nameParts[1], agg); - // break; - // } - - //case "geo_centroid": - // { - // var agg = JsonSerializer.Deserialize(ref reader, options); - // dictionary.Add(nameParts[1], agg); - // break; - // } - - //case "geo_line": - // { - // var agg = JsonSerializer.Deserialize(ref reader, options); - // dictionary.Add(nameParts[1], agg); - // break; - // } + case "geo_bounds": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "geo_centroid": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "geo_line": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } case "srareterms": { diff --git a/src/Elastic.Clients.Elasticsearch/Types/GeoLocation.cs b/src/Elastic.Clients.Elasticsearch/Types/GeoLocation.cs new file mode 100644 index 00000000000..e3a6e3b4d10 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Types/GeoLocation.cs @@ -0,0 +1,11 @@ +// 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. + +namespace Elastic.Clients.Elasticsearch; + +public partial class GeoLocation +{ + public static bool IsValidLatitude(double latitude) => latitude >= -90 && latitude <= 90; + public static bool IsValidLongitude(double longitude) => longitude >= -180 && longitude <= 180; +} diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AggregateDictionary.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AggregateDictionary.g.cs index 9f286fbc7ad..248a5070ea8 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AggregateDictionary.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AggregateDictionary.g.cs @@ -52,6 +52,8 @@ public AggregateDictionary(IReadOnlyDictionary backingDictio public Elastic.Clients.Elasticsearch.Aggregations.StatsBucketAggregate? GetStatsBucket(string key) => TryGet(key); public Elastic.Clients.Elasticsearch.Aggregations.ExtendedStatsAggregate? GetExtendedStats(string key) => TryGet(key); public Elastic.Clients.Elasticsearch.Aggregations.ExtendedStatsBucketAggregate? GetExtendedStatsBucket(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.GeoBoundsAggregate? GetGeoBounds(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.GeoCentroidAggregate? GetGeoCentroid(string key) => TryGet(key); public Elastic.Clients.Elasticsearch.Aggregations.HistogramAggregate? GetHistogram(string key) => TryGet(key); public Elastic.Clients.Elasticsearch.Aggregations.DateHistogramAggregate? GetDateHistogram(string key) => TryGet(key); public Elastic.Clients.Elasticsearch.Aggregations.AutoDateHistogramAggregate? GetAutoDateHistogram(string key) => TryGet(key); @@ -91,5 +93,6 @@ public AggregateDictionary(IReadOnlyDictionary backingDictio public Elastic.Clients.Elasticsearch.Aggregations.RateAggregate? GetRate(string key) => TryGet(key); public Elastic.Clients.Elasticsearch.Aggregations.CumulativeCardinalityAggregate? GetCumulativeCardinality(string key) => TryGet(key); public Elastic.Clients.Elasticsearch.Aggregations.MatrixStatsAggregate? GetMatrixStats(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.GeoLineAggregate? GetGeoLine(string key) => TryGet(key); private TAggregate TryGet(string key) where TAggregate : class, IAggregate => BackingDictionary.TryGetValue(key, out var agg) ? agg as TAggregate : null; } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/Aggregation.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/Aggregation.g.cs index b6492641c1c..5cd895bce0b 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/Aggregation.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/Aggregation.g.cs @@ -132,11 +132,26 @@ public override Aggregation Read(ref Utf8JsonReader reader, Type typeToConvert, return AggregationSerializationHelper.ReadContainer("filters", ref reader, options); } + if (propertyName == "geo_bounds") + { + return AggregationSerializationHelper.ReadContainer("geo_bounds", ref reader, options); + } + + if (propertyName == "geo_centroid") + { + return AggregationSerializationHelper.ReadContainer("geo_centroid", ref reader, options); + } + if (propertyName == "geo_distance") { return AggregationSerializationHelper.ReadContainer("geo_distance", ref reader, options); } + if (propertyName == "geo_line") + { + return AggregationSerializationHelper.ReadContainer("geo_line", ref reader, options); + } + if (propertyName == "geohash_grid") { return AggregationSerializationHelper.ReadContainer("geohash_grid", ref reader, options); @@ -430,11 +445,26 @@ public AggregationDescriptor Filters(string name, Action GeoBounds(string name, Action> configure) + { + return SetContainer(name, Aggregation.CreateWithAction("geo_bounds", configure)); + } + + public AggregationDescriptor GeoCentroid(string name, Action> configure) + { + return SetContainer(name, Aggregation.CreateWithAction("geo_centroid", configure)); + } + public AggregationDescriptor GeoDistance(string name, Action> configure) { return SetContainer(name, Aggregation.CreateWithAction("geo_distance", configure)); } + public AggregationDescriptor GeoLine(string name, Action> configure) + { + return SetContainer(name, Aggregation.CreateWithAction("geo_line", configure)); + } + public AggregationDescriptor GeohashGrid(string name, Action> configure) { return SetContainer(name, Aggregation.CreateWithAction("geohash_grid", configure)); @@ -769,6 +799,26 @@ public AggregationDescriptor Filters(string name, Action configure) + { + return SetContainer(name, Aggregation.CreateWithAction("geo_bounds", configure)); + } + + public AggregationDescriptor GeoBounds(string name, Action> configure) + { + return SetContainer(name, Aggregation.CreateWithAction("geo_bounds", configure)); + } + + public AggregationDescriptor GeoCentroid(string name, Action configure) + { + return SetContainer(name, Aggregation.CreateWithAction("geo_centroid", configure)); + } + + public AggregationDescriptor GeoCentroid(string name, Action> configure) + { + return SetContainer(name, Aggregation.CreateWithAction("geo_centroid", configure)); + } + public AggregationDescriptor GeoDistance(string name, Action configure) { return SetContainer(name, Aggregation.CreateWithAction("geo_distance", configure)); @@ -779,6 +829,16 @@ public AggregationDescriptor GeoDistance(string name, Action configure) + { + return SetContainer(name, Aggregation.CreateWithAction("geo_line", configure)); + } + + public AggregationDescriptor GeoLine(string name, Action> configure) + { + return SetContainer(name, Aggregation.CreateWithAction("geo_line", configure)); + } + public AggregationDescriptor GeohashGrid(string name, Action configure) { return SetContainer(name, Aggregation.CreateWithAction("geohash_grid", configure)); diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoBoundsAggregate.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoBoundsAggregate.g.cs new file mode 100644 index 00000000000..ddc34a2eb4e --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoBoundsAggregate.g.cs @@ -0,0 +1,36 @@ +// 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. +// +// ------------------------------------------------ + +#nullable restore + +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; + +namespace Elastic.Clients.Elasticsearch.Aggregations; + +public sealed partial class GeoBoundsAggregate : IAggregate +{ + [JsonInclude, JsonPropertyName("bounds")] + public Elastic.Clients.Elasticsearch.GeoBounds? Bounds { get; init; } + [JsonInclude, JsonPropertyName("meta")] + public IReadOnlyDictionary? Meta { get; init; } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoBoundsAggregation.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoBoundsAggregation.g.cs new file mode 100644 index 00000000000..00edbe132fd --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoBoundsAggregation.g.cs @@ -0,0 +1,357 @@ +// 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. +// +// ------------------------------------------------ + +#nullable restore + +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; + +namespace Elastic.Clients.Elasticsearch.Aggregations; + +internal sealed class GeoBoundsAggregationConverter : JsonConverter +{ + public override GeoBoundsAggregation Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + reader.Read(); + var aggName = reader.GetString(); + if (aggName != "geo_bounds") + throw new JsonException("Unexpected JSON detected."); + var agg = new GeoBoundsAggregation(aggName); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + if (reader.ValueTextEquals("field")) + { + reader.Read(); + var value = JsonSerializer.Deserialize(ref reader, options); + if (value is not null) + { + agg.Field = value; + } + + continue; + } + + if (reader.ValueTextEquals("missing")) + { + reader.Read(); + var value = JsonSerializer.Deserialize(ref reader, options); + if (value is not null) + { + agg.Missing = value; + } + + continue; + } + + if (reader.ValueTextEquals("script")) + { + reader.Read(); + var value = JsonSerializer.Deserialize(ref reader, options); + if (value is not null) + { + agg.Script = value; + } + + continue; + } + + if (reader.ValueTextEquals("wrap_longitude")) + { + reader.Read(); + var value = JsonSerializer.Deserialize(ref reader, options); + if (value is not null) + { + agg.WrapLongitude = value; + } + + continue; + } + } + } + + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + if (reader.ValueTextEquals("meta")) + { + var value = JsonSerializer.Deserialize>(ref reader, options); + if (value is not null) + { + agg.Meta = value; + } + + continue; + } + } + } + + return agg; + } + + public override void Write(Utf8JsonWriter writer, GeoBoundsAggregation value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + writer.WritePropertyName("geo_bounds"); + writer.WriteStartObject(); + if (value.Field is not null) + { + writer.WritePropertyName("field"); + JsonSerializer.Serialize(writer, value.Field, options); + } + + if (value.Missing is not null) + { + writer.WritePropertyName("missing"); + JsonSerializer.Serialize(writer, value.Missing, options); + } + + if (value.Script is not null) + { + writer.WritePropertyName("script"); + JsonSerializer.Serialize(writer, value.Script, options); + } + + if (value.WrapLongitude.HasValue) + { + writer.WritePropertyName("wrap_longitude"); + writer.WriteBooleanValue(value.WrapLongitude.Value); + } + + writer.WriteEndObject(); + if (value.Meta is not null) + { + writer.WritePropertyName("meta"); + JsonSerializer.Serialize(writer, value.Meta, options); + } + + writer.WriteEndObject(); + } +} + +[JsonConverter(typeof(GeoBoundsAggregationConverter))] +public sealed partial class GeoBoundsAggregation : SearchAggregation +{ + public GeoBoundsAggregation(string name, Field field) : this(name) => Field = field; + public GeoBoundsAggregation(string name) => Name = name; + + internal GeoBoundsAggregation() + { + } + + public Elastic.Clients.Elasticsearch.Field? Field { get; set; } + public IDictionary? Meta { get; set; } + public FieldValue? Missing { get; set; } + override public string? Name { get; internal set; } + public Elastic.Clients.Elasticsearch.Script? Script { get; set; } + public bool? WrapLongitude { get; set; } +} + +public sealed partial class GeoBoundsAggregationDescriptor : SerializableDescriptor> +{ + internal GeoBoundsAggregationDescriptor(Action> configure) => configure.Invoke(this); + + public GeoBoundsAggregationDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.Field? FieldValue { get; set; } + private IDictionary? MetaValue { get; set; } + private FieldValue? MissingValue { get; set; } + private Elastic.Clients.Elasticsearch.Script? ScriptValue { get; set; } + private bool? WrapLongitudeValue { get; set; } + + public GeoBoundsAggregationDescriptor Field(Elastic.Clients.Elasticsearch.Field? field) + { + FieldValue = field; + return Self; + } + + public GeoBoundsAggregationDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + public GeoBoundsAggregationDescriptor Meta(Func, FluentDictionary> selector) + { + MetaValue = selector?.Invoke(new FluentDictionary()); + return Self; + } + + public GeoBoundsAggregationDescriptor Missing(FieldValue? missing) + { + MissingValue = missing; + return Self; + } + + public GeoBoundsAggregationDescriptor Script(Elastic.Clients.Elasticsearch.Script? script) + { + ScriptValue = script; + return Self; + } + + public GeoBoundsAggregationDescriptor WrapLongitude(bool? wrapLongitude = true) + { + WrapLongitudeValue = wrapLongitude; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("geo_bounds"); + writer.WriteStartObject(); + if (FieldValue is not null) + { + writer.WritePropertyName("field"); + JsonSerializer.Serialize(writer, FieldValue, options); + } + + if (MissingValue is not null) + { + writer.WritePropertyName("missing"); + JsonSerializer.Serialize(writer, MissingValue, options); + } + + if (ScriptValue is not null) + { + writer.WritePropertyName("script"); + JsonSerializer.Serialize(writer, ScriptValue, options); + } + + if (WrapLongitudeValue.HasValue) + { + writer.WritePropertyName("wrap_longitude"); + writer.WriteBooleanValue(WrapLongitudeValue.Value); + } + + writer.WriteEndObject(); + if (MetaValue is not null) + { + writer.WritePropertyName("meta"); + JsonSerializer.Serialize(writer, MetaValue, options); + } + + writer.WriteEndObject(); + } +} + +public sealed partial class GeoBoundsAggregationDescriptor : SerializableDescriptor +{ + internal GeoBoundsAggregationDescriptor(Action configure) => configure.Invoke(this); + + public GeoBoundsAggregationDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.Field? FieldValue { get; set; } + private IDictionary? MetaValue { get; set; } + private FieldValue? MissingValue { get; set; } + private Elastic.Clients.Elasticsearch.Script? ScriptValue { get; set; } + private bool? WrapLongitudeValue { get; set; } + + public GeoBoundsAggregationDescriptor Field(Elastic.Clients.Elasticsearch.Field? field) + { + FieldValue = field; + return Self; + } + + public GeoBoundsAggregationDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + public GeoBoundsAggregationDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + public GeoBoundsAggregationDescriptor Meta(Func, FluentDictionary> selector) + { + MetaValue = selector?.Invoke(new FluentDictionary()); + return Self; + } + + public GeoBoundsAggregationDescriptor Missing(FieldValue? missing) + { + MissingValue = missing; + return Self; + } + + public GeoBoundsAggregationDescriptor Script(Elastic.Clients.Elasticsearch.Script? script) + { + ScriptValue = script; + return Self; + } + + public GeoBoundsAggregationDescriptor WrapLongitude(bool? wrapLongitude = true) + { + WrapLongitudeValue = wrapLongitude; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("geo_bounds"); + writer.WriteStartObject(); + if (FieldValue is not null) + { + writer.WritePropertyName("field"); + JsonSerializer.Serialize(writer, FieldValue, options); + } + + if (MissingValue is not null) + { + writer.WritePropertyName("missing"); + JsonSerializer.Serialize(writer, MissingValue, options); + } + + if (ScriptValue is not null) + { + writer.WritePropertyName("script"); + JsonSerializer.Serialize(writer, ScriptValue, options); + } + + if (WrapLongitudeValue.HasValue) + { + writer.WritePropertyName("wrap_longitude"); + writer.WriteBooleanValue(WrapLongitudeValue.Value); + } + + writer.WriteEndObject(); + if (MetaValue is not null) + { + writer.WritePropertyName("meta"); + JsonSerializer.Serialize(writer, MetaValue, options); + } + + writer.WriteEndObject(); + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoCentroidAggregate.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoCentroidAggregate.g.cs new file mode 100644 index 00000000000..4be076472e7 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoCentroidAggregate.g.cs @@ -0,0 +1,38 @@ +// 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. +// +// ------------------------------------------------ + +#nullable restore + +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; + +namespace Elastic.Clients.Elasticsearch.Aggregations; + +public sealed partial class GeoCentroidAggregate : IAggregate +{ + [JsonInclude, JsonPropertyName("count")] + public long Count { get; init; } + [JsonInclude, JsonPropertyName("location")] + public Elastic.Clients.Elasticsearch.GeoLocation? Location { get; init; } + [JsonInclude, JsonPropertyName("meta")] + public IReadOnlyDictionary? Meta { get; init; } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoCentroidAggregation.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoCentroidAggregation.g.cs new file mode 100644 index 00000000000..4cb9cefeb73 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoCentroidAggregation.g.cs @@ -0,0 +1,402 @@ +// 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. +// +// ------------------------------------------------ + +#nullable restore + +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; + +namespace Elastic.Clients.Elasticsearch.Aggregations; + +internal sealed class GeoCentroidAggregationConverter : JsonConverter +{ + public override GeoCentroidAggregation Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + reader.Read(); + var aggName = reader.GetString(); + if (aggName != "geo_centroid") + throw new JsonException("Unexpected JSON detected."); + var agg = new GeoCentroidAggregation(aggName); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + if (reader.ValueTextEquals("count")) + { + reader.Read(); + var value = JsonSerializer.Deserialize(ref reader, options); + if (value is not null) + { + agg.Count = value; + } + + continue; + } + + if (reader.ValueTextEquals("field")) + { + reader.Read(); + var value = JsonSerializer.Deserialize(ref reader, options); + if (value is not null) + { + agg.Field = value; + } + + continue; + } + + if (reader.ValueTextEquals("location")) + { + reader.Read(); + var value = JsonSerializer.Deserialize(ref reader, options); + if (value is not null) + { + agg.Location = value; + } + + continue; + } + + if (reader.ValueTextEquals("missing")) + { + reader.Read(); + var value = JsonSerializer.Deserialize(ref reader, options); + if (value is not null) + { + agg.Missing = value; + } + + continue; + } + + if (reader.ValueTextEquals("script")) + { + reader.Read(); + var value = JsonSerializer.Deserialize(ref reader, options); + if (value is not null) + { + agg.Script = value; + } + + continue; + } + } + } + + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + if (reader.ValueTextEquals("meta")) + { + var value = JsonSerializer.Deserialize>(ref reader, options); + if (value is not null) + { + agg.Meta = value; + } + + continue; + } + } + } + + return agg; + } + + public override void Write(Utf8JsonWriter writer, GeoCentroidAggregation value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + writer.WritePropertyName("geo_centroid"); + writer.WriteStartObject(); + if (value.Count.HasValue) + { + writer.WritePropertyName("count"); + writer.WriteNumberValue(value.Count.Value); + } + + if (value.Field is not null) + { + writer.WritePropertyName("field"); + JsonSerializer.Serialize(writer, value.Field, options); + } + + if (value.Location is not null) + { + writer.WritePropertyName("location"); + JsonSerializer.Serialize(writer, value.Location, options); + } + + if (value.Missing is not null) + { + writer.WritePropertyName("missing"); + JsonSerializer.Serialize(writer, value.Missing, options); + } + + if (value.Script is not null) + { + writer.WritePropertyName("script"); + JsonSerializer.Serialize(writer, value.Script, options); + } + + writer.WriteEndObject(); + if (value.Meta is not null) + { + writer.WritePropertyName("meta"); + JsonSerializer.Serialize(writer, value.Meta, options); + } + + writer.WriteEndObject(); + } +} + +[JsonConverter(typeof(GeoCentroidAggregationConverter))] +public sealed partial class GeoCentroidAggregation : SearchAggregation +{ + public GeoCentroidAggregation(string name, Field field) : this(name) => Field = field; + public GeoCentroidAggregation(string name) => Name = name; + + internal GeoCentroidAggregation() + { + } + + public long? Count { get; set; } + public Elastic.Clients.Elasticsearch.Field? Field { get; set; } + public Elastic.Clients.Elasticsearch.GeoLocation? Location { get; set; } + public IDictionary? Meta { get; set; } + public FieldValue? Missing { get; set; } + override public string? Name { get; internal set; } + public Elastic.Clients.Elasticsearch.Script? Script { get; set; } +} + +public sealed partial class GeoCentroidAggregationDescriptor : SerializableDescriptor> +{ + internal GeoCentroidAggregationDescriptor(Action> configure) => configure.Invoke(this); + + public GeoCentroidAggregationDescriptor() : base() + { + } + + private long? CountValue { get; set; } + private Elastic.Clients.Elasticsearch.Field? FieldValue { get; set; } + private Elastic.Clients.Elasticsearch.GeoLocation? LocationValue { get; set; } + private IDictionary? MetaValue { get; set; } + private FieldValue? MissingValue { get; set; } + private Elastic.Clients.Elasticsearch.Script? ScriptValue { get; set; } + + public GeoCentroidAggregationDescriptor Count(long? count) + { + CountValue = count; + return Self; + } + + public GeoCentroidAggregationDescriptor Field(Elastic.Clients.Elasticsearch.Field? field) + { + FieldValue = field; + return Self; + } + + public GeoCentroidAggregationDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + public GeoCentroidAggregationDescriptor Location(Elastic.Clients.Elasticsearch.GeoLocation? location) + { + LocationValue = location; + return Self; + } + + public GeoCentroidAggregationDescriptor Meta(Func, FluentDictionary> selector) + { + MetaValue = selector?.Invoke(new FluentDictionary()); + return Self; + } + + public GeoCentroidAggregationDescriptor Missing(FieldValue? missing) + { + MissingValue = missing; + return Self; + } + + public GeoCentroidAggregationDescriptor Script(Elastic.Clients.Elasticsearch.Script? script) + { + ScriptValue = script; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("geo_centroid"); + writer.WriteStartObject(); + if (CountValue.HasValue) + { + writer.WritePropertyName("count"); + writer.WriteNumberValue(CountValue.Value); + } + + if (FieldValue is not null) + { + writer.WritePropertyName("field"); + JsonSerializer.Serialize(writer, FieldValue, options); + } + + if (LocationValue is not null) + { + writer.WritePropertyName("location"); + JsonSerializer.Serialize(writer, LocationValue, options); + } + + if (MissingValue is not null) + { + writer.WritePropertyName("missing"); + JsonSerializer.Serialize(writer, MissingValue, options); + } + + if (ScriptValue is not null) + { + writer.WritePropertyName("script"); + JsonSerializer.Serialize(writer, ScriptValue, options); + } + + writer.WriteEndObject(); + if (MetaValue is not null) + { + writer.WritePropertyName("meta"); + JsonSerializer.Serialize(writer, MetaValue, options); + } + + writer.WriteEndObject(); + } +} + +public sealed partial class GeoCentroidAggregationDescriptor : SerializableDescriptor +{ + internal GeoCentroidAggregationDescriptor(Action configure) => configure.Invoke(this); + + public GeoCentroidAggregationDescriptor() : base() + { + } + + private long? CountValue { get; set; } + private Elastic.Clients.Elasticsearch.Field? FieldValue { get; set; } + private Elastic.Clients.Elasticsearch.GeoLocation? LocationValue { get; set; } + private IDictionary? MetaValue { get; set; } + private FieldValue? MissingValue { get; set; } + private Elastic.Clients.Elasticsearch.Script? ScriptValue { get; set; } + + public GeoCentroidAggregationDescriptor Count(long? count) + { + CountValue = count; + return Self; + } + + public GeoCentroidAggregationDescriptor Field(Elastic.Clients.Elasticsearch.Field? field) + { + FieldValue = field; + return Self; + } + + public GeoCentroidAggregationDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + public GeoCentroidAggregationDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + public GeoCentroidAggregationDescriptor Location(Elastic.Clients.Elasticsearch.GeoLocation? location) + { + LocationValue = location; + return Self; + } + + public GeoCentroidAggregationDescriptor Meta(Func, FluentDictionary> selector) + { + MetaValue = selector?.Invoke(new FluentDictionary()); + return Self; + } + + public GeoCentroidAggregationDescriptor Missing(FieldValue? missing) + { + MissingValue = missing; + return Self; + } + + public GeoCentroidAggregationDescriptor Script(Elastic.Clients.Elasticsearch.Script? script) + { + ScriptValue = script; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("geo_centroid"); + writer.WriteStartObject(); + if (CountValue.HasValue) + { + writer.WritePropertyName("count"); + writer.WriteNumberValue(CountValue.Value); + } + + if (FieldValue is not null) + { + writer.WritePropertyName("field"); + JsonSerializer.Serialize(writer, FieldValue, options); + } + + if (LocationValue is not null) + { + writer.WritePropertyName("location"); + JsonSerializer.Serialize(writer, LocationValue, options); + } + + if (MissingValue is not null) + { + writer.WritePropertyName("missing"); + JsonSerializer.Serialize(writer, MissingValue, options); + } + + if (ScriptValue is not null) + { + writer.WritePropertyName("script"); + JsonSerializer.Serialize(writer, ScriptValue, options); + } + + writer.WriteEndObject(); + if (MetaValue is not null) + { + writer.WritePropertyName("meta"); + JsonSerializer.Serialize(writer, MetaValue, options); + } + + writer.WriteEndObject(); + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoLineAggregate.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoLineAggregate.g.cs new file mode 100644 index 00000000000..5191273fae9 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoLineAggregate.g.cs @@ -0,0 +1,40 @@ +// 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. +// +// ------------------------------------------------ + +#nullable restore + +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; + +namespace Elastic.Clients.Elasticsearch.Aggregations; + +public sealed partial class GeoLineAggregate : IAggregate +{ + [JsonInclude, JsonPropertyName("geometry")] + public Elastic.Clients.Elasticsearch.GeoLine Geometry { get; init; } + [JsonInclude, JsonPropertyName("meta")] + public IReadOnlyDictionary? Meta { get; init; } + [JsonInclude, JsonPropertyName("properties")] + public object Properties { get; init; } + [JsonInclude, JsonPropertyName("type")] + public string Type { get; init; } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoLineAggregation.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoLineAggregation.g.cs new file mode 100644 index 00000000000..9b0358db46a --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoLineAggregation.g.cs @@ -0,0 +1,487 @@ +// 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. +// +// ------------------------------------------------ + +#nullable restore + +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; + +namespace Elastic.Clients.Elasticsearch.Aggregations; + +internal sealed class GeoLineAggregationConverter : JsonConverter +{ + public override GeoLineAggregation Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + reader.Read(); + var aggName = reader.GetString(); + if (aggName != "geo_line") + throw new JsonException("Unexpected JSON detected."); + var agg = new GeoLineAggregation(aggName); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + if (reader.ValueTextEquals("include_sort")) + { + reader.Read(); + var value = JsonSerializer.Deserialize(ref reader, options); + if (value is not null) + { + agg.IncludeSort = value; + } + + continue; + } + + if (reader.ValueTextEquals("point")) + { + reader.Read(); + var value = JsonSerializer.Deserialize(ref reader, options); + agg.Point = value; + continue; + } + + if (reader.ValueTextEquals("size")) + { + reader.Read(); + var value = JsonSerializer.Deserialize(ref reader, options); + if (value is not null) + { + agg.Size = value; + } + + continue; + } + + if (reader.ValueTextEquals("sort")) + { + reader.Read(); + var value = JsonSerializer.Deserialize(ref reader, options); + agg.Sort = value; + continue; + } + + if (reader.ValueTextEquals("sort_order")) + { + reader.Read(); + var value = JsonSerializer.Deserialize(ref reader, options); + if (value is not null) + { + agg.SortOrder = value; + } + + continue; + } + } + } + + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + if (reader.ValueTextEquals("meta")) + { + var value = JsonSerializer.Deserialize>(ref reader, options); + if (value is not null) + { + agg.Meta = value; + } + + continue; + } + } + } + + return agg; + } + + public override void Write(Utf8JsonWriter writer, GeoLineAggregation value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + writer.WritePropertyName("geo_line"); + writer.WriteStartObject(); + if (value.IncludeSort.HasValue) + { + writer.WritePropertyName("include_sort"); + writer.WriteBooleanValue(value.IncludeSort.Value); + } + + writer.WritePropertyName("point"); + JsonSerializer.Serialize(writer, value.Point, options); + if (value.Size.HasValue) + { + writer.WritePropertyName("size"); + writer.WriteNumberValue(value.Size.Value); + } + + writer.WritePropertyName("sort"); + JsonSerializer.Serialize(writer, value.Sort, options); + if (value.SortOrder is not null) + { + writer.WritePropertyName("sort_order"); + JsonSerializer.Serialize(writer, value.SortOrder, options); + } + + writer.WriteEndObject(); + if (value.Meta is not null) + { + writer.WritePropertyName("meta"); + JsonSerializer.Serialize(writer, value.Meta, options); + } + + writer.WriteEndObject(); + } +} + +[JsonConverter(typeof(GeoLineAggregationConverter))] +public sealed partial class GeoLineAggregation : SearchAggregation +{ + public GeoLineAggregation(string name) => Name = name; + + internal GeoLineAggregation() + { + } + + public bool? IncludeSort { get; set; } + public IDictionary? Meta { get; set; } + override public string? Name { get; internal set; } + public Elastic.Clients.Elasticsearch.Aggregations.GeoLinePoint Point { get; set; } + public int? Size { get; set; } + public Elastic.Clients.Elasticsearch.Aggregations.GeoLineSort Sort { get; set; } + public Elastic.Clients.Elasticsearch.SortOrder? SortOrder { get; set; } +} + +public sealed partial class GeoLineAggregationDescriptor : SerializableDescriptor> +{ + internal GeoLineAggregationDescriptor(Action> configure) => configure.Invoke(this); + + public GeoLineAggregationDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.Aggregations.GeoLinePoint PointValue { get; set; } + private GeoLinePointDescriptor PointDescriptor { get; set; } + private Action> PointDescriptorAction { get; set; } + private Elastic.Clients.Elasticsearch.Aggregations.GeoLineSort SortValue { get; set; } + private GeoLineSortDescriptor SortDescriptor { get; set; } + private Action> SortDescriptorAction { get; set; } + private bool? IncludeSortValue { get; set; } + private IDictionary? MetaValue { get; set; } + private int? SizeValue { get; set; } + private Elastic.Clients.Elasticsearch.SortOrder? SortOrderValue { get; set; } + + public GeoLineAggregationDescriptor Point(Elastic.Clients.Elasticsearch.Aggregations.GeoLinePoint point) + { + PointDescriptor = null; + PointDescriptorAction = null; + PointValue = point; + return Self; + } + + public GeoLineAggregationDescriptor Point(GeoLinePointDescriptor descriptor) + { + PointValue = null; + PointDescriptorAction = null; + PointDescriptor = descriptor; + return Self; + } + + public GeoLineAggregationDescriptor Point(Action> configure) + { + PointValue = null; + PointDescriptor = null; + PointDescriptorAction = configure; + return Self; + } + + public GeoLineAggregationDescriptor Sort(Elastic.Clients.Elasticsearch.Aggregations.GeoLineSort sort) + { + SortDescriptor = null; + SortDescriptorAction = null; + SortValue = sort; + return Self; + } + + public GeoLineAggregationDescriptor Sort(GeoLineSortDescriptor descriptor) + { + SortValue = null; + SortDescriptorAction = null; + SortDescriptor = descriptor; + return Self; + } + + public GeoLineAggregationDescriptor Sort(Action> configure) + { + SortValue = null; + SortDescriptor = null; + SortDescriptorAction = configure; + return Self; + } + + public GeoLineAggregationDescriptor IncludeSort(bool? includeSort = true) + { + IncludeSortValue = includeSort; + return Self; + } + + public GeoLineAggregationDescriptor Meta(Func, FluentDictionary> selector) + { + MetaValue = selector?.Invoke(new FluentDictionary()); + return Self; + } + + public GeoLineAggregationDescriptor Size(int? size) + { + SizeValue = size; + return Self; + } + + public GeoLineAggregationDescriptor SortOrder(Elastic.Clients.Elasticsearch.SortOrder? sortOrder) + { + SortOrderValue = sortOrder; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("geo_line"); + writer.WriteStartObject(); + if (PointDescriptor is not null) + { + writer.WritePropertyName("point"); + JsonSerializer.Serialize(writer, PointDescriptor, options); + } + else if (PointDescriptorAction is not null) + { + writer.WritePropertyName("point"); + JsonSerializer.Serialize(writer, new GeoLinePointDescriptor(PointDescriptorAction), options); + } + else + { + writer.WritePropertyName("point"); + JsonSerializer.Serialize(writer, PointValue, options); + } + + if (SortDescriptor is not null) + { + writer.WritePropertyName("sort"); + JsonSerializer.Serialize(writer, SortDescriptor, options); + } + else if (SortDescriptorAction is not null) + { + writer.WritePropertyName("sort"); + JsonSerializer.Serialize(writer, new GeoLineSortDescriptor(SortDescriptorAction), options); + } + else + { + writer.WritePropertyName("sort"); + JsonSerializer.Serialize(writer, SortValue, options); + } + + if (IncludeSortValue.HasValue) + { + writer.WritePropertyName("include_sort"); + writer.WriteBooleanValue(IncludeSortValue.Value); + } + + if (SizeValue.HasValue) + { + writer.WritePropertyName("size"); + writer.WriteNumberValue(SizeValue.Value); + } + + if (SortOrderValue is not null) + { + writer.WritePropertyName("sort_order"); + JsonSerializer.Serialize(writer, SortOrderValue, options); + } + + writer.WriteEndObject(); + if (MetaValue is not null) + { + writer.WritePropertyName("meta"); + JsonSerializer.Serialize(writer, MetaValue, options); + } + + writer.WriteEndObject(); + } +} + +public sealed partial class GeoLineAggregationDescriptor : SerializableDescriptor +{ + internal GeoLineAggregationDescriptor(Action configure) => configure.Invoke(this); + + public GeoLineAggregationDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.Aggregations.GeoLinePoint PointValue { get; set; } + private GeoLinePointDescriptor PointDescriptor { get; set; } + private Action PointDescriptorAction { get; set; } + private Elastic.Clients.Elasticsearch.Aggregations.GeoLineSort SortValue { get; set; } + private GeoLineSortDescriptor SortDescriptor { get; set; } + private Action SortDescriptorAction { get; set; } + private bool? IncludeSortValue { get; set; } + private IDictionary? MetaValue { get; set; } + private int? SizeValue { get; set; } + private Elastic.Clients.Elasticsearch.SortOrder? SortOrderValue { get; set; } + + public GeoLineAggregationDescriptor Point(Elastic.Clients.Elasticsearch.Aggregations.GeoLinePoint point) + { + PointDescriptor = null; + PointDescriptorAction = null; + PointValue = point; + return Self; + } + + public GeoLineAggregationDescriptor Point(GeoLinePointDescriptor descriptor) + { + PointValue = null; + PointDescriptorAction = null; + PointDescriptor = descriptor; + return Self; + } + + public GeoLineAggregationDescriptor Point(Action configure) + { + PointValue = null; + PointDescriptor = null; + PointDescriptorAction = configure; + return Self; + } + + public GeoLineAggregationDescriptor Sort(Elastic.Clients.Elasticsearch.Aggregations.GeoLineSort sort) + { + SortDescriptor = null; + SortDescriptorAction = null; + SortValue = sort; + return Self; + } + + public GeoLineAggregationDescriptor Sort(GeoLineSortDescriptor descriptor) + { + SortValue = null; + SortDescriptorAction = null; + SortDescriptor = descriptor; + return Self; + } + + public GeoLineAggregationDescriptor Sort(Action configure) + { + SortValue = null; + SortDescriptor = null; + SortDescriptorAction = configure; + return Self; + } + + public GeoLineAggregationDescriptor IncludeSort(bool? includeSort = true) + { + IncludeSortValue = includeSort; + return Self; + } + + public GeoLineAggregationDescriptor Meta(Func, FluentDictionary> selector) + { + MetaValue = selector?.Invoke(new FluentDictionary()); + return Self; + } + + public GeoLineAggregationDescriptor Size(int? size) + { + SizeValue = size; + return Self; + } + + public GeoLineAggregationDescriptor SortOrder(Elastic.Clients.Elasticsearch.SortOrder? sortOrder) + { + SortOrderValue = sortOrder; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("geo_line"); + writer.WriteStartObject(); + if (PointDescriptor is not null) + { + writer.WritePropertyName("point"); + JsonSerializer.Serialize(writer, PointDescriptor, options); + } + else if (PointDescriptorAction is not null) + { + writer.WritePropertyName("point"); + JsonSerializer.Serialize(writer, new GeoLinePointDescriptor(PointDescriptorAction), options); + } + else + { + writer.WritePropertyName("point"); + JsonSerializer.Serialize(writer, PointValue, options); + } + + if (SortDescriptor is not null) + { + writer.WritePropertyName("sort"); + JsonSerializer.Serialize(writer, SortDescriptor, options); + } + else if (SortDescriptorAction is not null) + { + writer.WritePropertyName("sort"); + JsonSerializer.Serialize(writer, new GeoLineSortDescriptor(SortDescriptorAction), options); + } + else + { + writer.WritePropertyName("sort"); + JsonSerializer.Serialize(writer, SortValue, options); + } + + if (IncludeSortValue.HasValue) + { + writer.WritePropertyName("include_sort"); + writer.WriteBooleanValue(IncludeSortValue.Value); + } + + if (SizeValue.HasValue) + { + writer.WritePropertyName("size"); + writer.WriteNumberValue(SizeValue.Value); + } + + if (SortOrderValue is not null) + { + writer.WritePropertyName("sort_order"); + JsonSerializer.Serialize(writer, SortOrderValue, options); + } + + writer.WriteEndObject(); + if (MetaValue is not null) + { + writer.WritePropertyName("meta"); + JsonSerializer.Serialize(writer, MetaValue, options); + } + + writer.WriteEndObject(); + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoLinePoint.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoLinePoint.g.cs new file mode 100644 index 00000000000..1e74f52c307 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoLinePoint.g.cs @@ -0,0 +1,102 @@ +// 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. +// +// ------------------------------------------------ + +#nullable restore + +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; + +namespace Elastic.Clients.Elasticsearch.Aggregations; + +public sealed partial class GeoLinePoint +{ + [JsonInclude, JsonPropertyName("field")] + public Elastic.Clients.Elasticsearch.Field Field { get; set; } +} + +public sealed partial class GeoLinePointDescriptor : SerializableDescriptor> +{ + internal GeoLinePointDescriptor(Action> configure) => configure.Invoke(this); + + public GeoLinePointDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + public GeoLinePointDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public GeoLinePointDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("field"); + JsonSerializer.Serialize(writer, FieldValue, options); + writer.WriteEndObject(); + } +} + +public sealed partial class GeoLinePointDescriptor : SerializableDescriptor +{ + internal GeoLinePointDescriptor(Action configure) => configure.Invoke(this); + + public GeoLinePointDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + public GeoLinePointDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public GeoLinePointDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + public GeoLinePointDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("field"); + JsonSerializer.Serialize(writer, FieldValue, options); + writer.WriteEndObject(); + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoLineSort.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoLineSort.g.cs new file mode 100644 index 00000000000..335562f4eee --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GeoLineSort.g.cs @@ -0,0 +1,102 @@ +// 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. +// +// ------------------------------------------------ + +#nullable restore + +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; + +namespace Elastic.Clients.Elasticsearch.Aggregations; + +public sealed partial class GeoLineSort +{ + [JsonInclude, JsonPropertyName("field")] + public Elastic.Clients.Elasticsearch.Field Field { get; set; } +} + +public sealed partial class GeoLineSortDescriptor : SerializableDescriptor> +{ + internal GeoLineSortDescriptor(Action> configure) => configure.Invoke(this); + + public GeoLineSortDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + public GeoLineSortDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public GeoLineSortDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("field"); + JsonSerializer.Serialize(writer, FieldValue, options); + writer.WriteEndObject(); + } +} + +public sealed partial class GeoLineSortDescriptor : SerializableDescriptor +{ + internal GeoLineSortDescriptor(Action configure) => configure.Invoke(this); + + public GeoLineSortDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; } + + public GeoLineSortDescriptor Field(Elastic.Clients.Elasticsearch.Field field) + { + FieldValue = field; + return Self; + } + + public GeoLineSortDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + public GeoLineSortDescriptor Field(Expression> field) + { + FieldValue = field; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("field"); + JsonSerializer.Serialize(writer, FieldValue, options); + writer.WriteEndObject(); + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/GeoLine.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/GeoLine.g.cs new file mode 100644 index 00000000000..7af28fe1bdc --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/GeoLine.g.cs @@ -0,0 +1,46 @@ +// 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. +// +// ------------------------------------------------ + +#nullable restore + +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; + +namespace Elastic.Clients.Elasticsearch; + +/// +/// A GeoJson GeoLine. +/// +public sealed partial class GeoLine +{ + /// + /// Array of `[lon, lat]` coordinates + /// + [JsonInclude, JsonPropertyName("coordinates")] + public IReadOnlyCollection> Coordinates { get; init; } + + /// + /// Always `"LineString"` + /// + [JsonInclude, JsonPropertyName("type")] + public string Type { get; init; } +} \ No newline at end of file diff --git a/tests/Tests.Core/Extensions/ClientExtensions.cs b/tests/Tests.Core/Extensions/ClientExtensions.cs index e8a3054ce5f..9357db949d5 100644 --- a/tests/Tests.Core/Extensions/ClientExtensions.cs +++ b/tests/Tests.Core/Extensions/ClientExtensions.cs @@ -4,16 +4,19 @@ //using Elastic.Clients.Elasticsearch.Cluster; +using Elastic.Clients.Elasticsearch; +using Elastic.Clients.Elasticsearch.Cluster; + namespace Tests.Core.Extensions { public static class ClientExtensions { - //public static HealthResponse WaitForSecurityIndices(this IElasticsearchClient client) => - // client.Cluster.Health( - // new HealthRequest(".security-*") - // { - // WaitForStatus = WaitForStatus.Green /*, ExpandWildcards = ExpandWildcards.All*/ - // }); + public static HealthResponse WaitForSecurityIndices(this ElasticsearchClient client) => + client.Cluster.Health( + new HealthRequest(".security-*") + { + WaitForStatus = HealthStatus.Green + }); //public static async Task WaitForSecurityIndicesAsync(this IElasticsearchClient client) => // await client.Cluster.HealthAsync( diff --git a/tests/Tests.Core/ManagedElasticsearch/Clusters/XPackCluster.cs b/tests/Tests.Core/ManagedElasticsearch/Clusters/XPackCluster.cs new file mode 100644 index 00000000000..2a1ecb81820 --- /dev/null +++ b/tests/Tests.Core/ManagedElasticsearch/Clusters/XPackCluster.cs @@ -0,0 +1,70 @@ +// 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 System.IO; +using Elastic.Elasticsearch.Ephemeral; +using Elastic.Elasticsearch.Xunit; +using Elastic.Stack.ArtifactsApi.Products; +using Elastic.Clients.Elasticsearch; +using Elastic.Clients.Elasticsearch.Cluster; +using Tests.Core.Extensions; +using Tests.Core.ManagedElasticsearch.Tasks; +using Tests.Domain.Extensions; +using System; +using Elastic.Transport; +using Tests.Core.ManagedElasticsearch.NodeSeeders; + +namespace Tests.Core.ManagedElasticsearch.Clusters; + +public class XPackClusterConfiguration : ClientTestClusterConfiguration +{ + public XPackClusterConfiguration() : this(ClusterFeatures.SSL | ClusterFeatures.Security) { } + + public XPackClusterConfiguration(ClusterFeatures features) : base(ClusterFeatures.XPack | features, 1, ElasticsearchPlugin.IngestAttachment) + { + var isSnapshot = !string.IsNullOrEmpty(Version.PreRelease) && Version.PreRelease.ToLower().Contains("snapshot"); + + // Get license file path from environment variable + var licenseFilePath = Environment.GetEnvironmentVariable("ES_LICENSE_FILE"); + + if (!isSnapshot && !string.IsNullOrEmpty(licenseFilePath) && File.Exists(licenseFilePath)) + { + var licenseContents = File.ReadAllText(licenseFilePath); + XPackLicenseJson = licenseContents; + } + TrialMode = XPackTrialMode.Trial; + + AdditionalBeforeNodeStartedTasks.Add(new EnsureWatcherActionConfigurationInElasticsearchYaml()); + AdditionalBeforeNodeStartedTasks.Add(new EnsureWatcherActionConfigurationSecretsInKeystore()); + AdditionalBeforeNodeStartedTasks.Add(new EnsureNativeSecurityRealmEnabledInElasticsearchYaml()); + + ShowElasticsearchOutputAfterStarted = true; + } +} + +public class XPackCluster : XunitClusterBase, ITestCluster +{ + public XPackCluster() : this(new XPackClusterConfiguration()) { } + + public XPackCluster(XPackClusterConfiguration configuration) : base(configuration) { } + + public ElasticsearchClient Client => this.GetOrAddClient(s => Authenticate(ConnectionSettings(s.ApplyDomainSettings()))); + + protected virtual ElasticsearchClientSettings Authenticate(ElasticsearchClientSettings s) => s + .Authentication(new BasicAuthentication(ClusterAuthentication.Admin.Username, ClusterAuthentication.Admin.Password)); + + protected virtual ElasticsearchClientSettings ConnectionSettings(ElasticsearchClientSettings s) => s + .ServerCertificateValidationCallback(CertificateValidations.AllowAll); + + protected sealed override void SeedCluster() + { + Client.Cluster.Health(new HealthRequest { WaitForStatus = HealthStatus.Green }); + Client.WaitForSecurityIndices(); + SeedNode(); + Client.Cluster.Health(new HealthRequest { WaitForStatus = HealthStatus.Green }); + Client.WaitForSecurityIndices(); + } + + protected virtual void SeedNode() => new DefaultSeeder(Client).SeedNode(); +} diff --git a/tests/Tests.Core/ManagedElasticsearch/Tasks/EnsureNativeSecurityRealmEnabledInElasticsearchYaml.cs b/tests/Tests.Core/ManagedElasticsearch/Tasks/EnsureNativeSecurityRealmEnabledInElasticsearchYaml.cs index 45ccc13f1c8..fe94f014c48 100644 --- a/tests/Tests.Core/ManagedElasticsearch/Tasks/EnsureNativeSecurityRealmEnabledInElasticsearchYaml.cs +++ b/tests/Tests.Core/ManagedElasticsearch/Tasks/EnsureNativeSecurityRealmEnabledInElasticsearchYaml.cs @@ -26,18 +26,11 @@ public override void Run(IEphemeralCluster cluste if (line.Contains("realms:")) { - var collection = cluster.ClusterConfiguration.Version >= "7.0.0-alpha1" - ? new[] - { - " native.native1:", - " order: 2" - } - : new[] - { - " native1:", - " type: native", - " order: 2" - }; + var collection = new[] + { + " native.native1:", + " order: 2" + }; modifiedLines.AddRange(collection); modified = true; @@ -46,30 +39,18 @@ public override void Run(IEphemeralCluster cluste if (!modified) { - var collection = cluster.ClusterConfiguration.Version >= "7.0.0-alpha1" - ? new[] - { - string.Empty, - "xpack:", - " security:", - " authc:", - " realms:", - " native1:", - " type: native", - " order: 0", - string.Empty - } - : new[] - { - string.Empty, - "xpack:", - " security:", - " authc:", - " realms:", - " native.native1:", - " order: 0", - string.Empty - }; + var collection = new[] + { + string.Empty, + "xpack:", + " security:", + " authc:", + " realms:", + " native1:", + " type: native", + " order: 0", + string.Empty + }; modifiedLines.AddRange(collection); } diff --git a/tests/Tests/Aggregations/Metric/GeoBoundsAggregationUsageTests.cs b/tests/Tests/Aggregations/Metric/GeoBoundsAggregationUsageTests.cs new file mode 100644 index 00000000000..929774a32a7 --- /dev/null +++ b/tests/Tests/Aggregations/Metric/GeoBoundsAggregationUsageTests.cs @@ -0,0 +1,52 @@ +// 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 System; +using Elastic.Clients.Elasticsearch.Aggregations; +using Tests.Core.ManagedElasticsearch.Clusters; +using Tests.Domain; +using Tests.Core.Extensions; +using Tests.Framework.EndpointTests.TestState; + +namespace Tests.Aggregations.Metric; + +public class GeoBoundsAggregationUsageTests : AggregationUsageWithVerifyTestBase +{ + public GeoBoundsAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + + protected override Action> FluentAggregations => a => a + .GeoBounds("viewport", gb => gb + .Field(p => p.LocationPoint) + .WrapLongitude() + ); + + protected override AggregationDictionary InitializerAggregations => + new GeoBoundsAggregation("viewport", Infer.Field(p => p.LocationPoint)) + { + WrapLongitude = true + }; + + protected override void ExpectResponse(SearchResponse response) + { + response.ShouldBeValid(); + response.Aggregations.Count.Should().Be(1); + + var viewport = response.Aggregations.GetGeoBounds("viewport"); + viewport.Should().NotBeNull(); + viewport.Bounds.Should().NotBeNull(); + + viewport.Bounds.IsTopLeftBottomRight.Should().BeTrue(); + viewport.Bounds.TryGetTopLeftBottomRight(out var topLeftBottomRight).Should().BeTrue(); + topLeftBottomRight.BottomRight.IsLatitudeLongitude.Should().BeTrue(); + topLeftBottomRight.BottomRight.TryGetLatitudeLongitude(out var bottomRightLatLon).Should().BeTrue(); + topLeftBottomRight.TopLeft.IsLatitudeLongitude.Should().BeTrue(); + topLeftBottomRight.TopLeft.TryGetLatitudeLongitude(out var topLeftLatLon).Should().BeTrue(); + + GeoLocation.IsValidLatitude(bottomRightLatLon.Lat).Should().BeTrue(); + GeoLocation.IsValidLongitude(bottomRightLatLon.Lon).Should().BeTrue(); + GeoLocation.IsValidLatitude(topLeftLatLon.Lat).Should().BeTrue(); + GeoLocation.IsValidLongitude(topLeftLatLon.Lon).Should().BeTrue(); + } +} + diff --git a/tests/Tests/Aggregations/Metric/GeoCentroidAggregationUsageTests.cs b/tests/Tests/Aggregations/Metric/GeoCentroidAggregationUsageTests.cs new file mode 100644 index 00000000000..baf1e564c3f --- /dev/null +++ b/tests/Tests/Aggregations/Metric/GeoCentroidAggregationUsageTests.cs @@ -0,0 +1,119 @@ +// 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 System; +using Elastic.Clients.Elasticsearch.Aggregations; +using Tests.Core.ManagedElasticsearch.Clusters; +using Tests.Domain; +using Tests.Core.Extensions; +using Tests.Framework.EndpointTests.TestState; +using Elastic.Clients.Elasticsearch.Experimental; +using Elastic.Clients.Elasticsearch.QueryDsl; + +namespace Tests.Aggregations.Metric; + +public class GeoCentroidAggregationUsageTests : AggregationUsageWithVerifyTestBase +{ + public GeoCentroidAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + + protected override Action> FluentAggregations => a => a + .GeoCentroid("centroid", gb => gb + .Field(p => p.LocationPoint) + ); + + protected override AggregationDictionary InitializerAggregations => + new GeoCentroidAggregation("centroid", Infer.Field(p => p.LocationPoint)); + + protected override void ExpectResponse(SearchResponse response) + { + response.ShouldBeValid(); + response.Aggregations.Count.Should().Be(1); + + var centroid = response.Aggregations.GetGeoCentroid("centroid"); + centroid.Should().NotBeNull(); + centroid.Count.Should().BeGreaterThan(0); + centroid.Location.Should().NotBeNull(); + + centroid.Location.IsLatitudeLongitude.Should().BeTrue(); + centroid.Location.TryGetLatitudeLongitude(out var centroidLatLon).Should().BeTrue(); + centroidLatLon.Lat.Should().NotBe(0); + centroidLatLon.Lon.Should().NotBe(0); + + GeoLocation.IsValidLatitude(centroidLatLon.Lat).Should().BeTrue(); + GeoLocation.IsValidLongitude(centroidLatLon.Lon).Should().BeTrue(); + } +} + +public class NestedGeoCentroidAggregationUsageTests : AggregationUsageWithVerifyTestBase +{ + public NestedGeoCentroidAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage) { } + + // The `geo_centroid` aggregation is more interesting when combined as a sub-aggregation to other bucket aggregations + + protected override Action> FluentAggregations => a => a + .Terms("projects", t => t + .Field(p => p.Name) + .Aggregations(sa => sa + .GeoCentroid("centroid", gb => gb + .Field(p => p.LocationPoint) + ) + ) + ); + + protected override AggregationDictionary InitializerAggregations => + new TermsAggregation("projects") + { + Field = Infer.Field(p => p.Name), + Aggregations = new GeoCentroidAggregation("centroid", Infer.Field(p => p.LocationPoint)) + }; + + protected override void ExpectResponse(SearchResponse response) + { + response.ShouldBeValid(); + + var projects = response.Aggregations.GetTerms("projects"); + + foreach (var bucket in projects.Buckets) + { + var centroid = bucket.GetGeoCentroid("centroid"); + + centroid.Should().NotBeNull(); + centroid.Count.Should().BeGreaterThan(0); + centroid.Location.Should().NotBeNull(); + + centroid.Location.IsLatitudeLongitude.Should().BeTrue(); + centroid.Location.TryGetLatitudeLongitude(out var centroidLatLon).Should().BeTrue(); + centroidLatLon.Lat.Should().NotBe(0); + centroidLatLon.Lon.Should().NotBe(0); + + GeoLocation.IsValidLatitude(centroidLatLon.Lat).Should().BeTrue(); + GeoLocation.IsValidLongitude(centroidLatLon.Lon).Should().BeTrue(); + } + } +} + +public class GeoCentroidNoResultsAggregationUsageTests : AggregationUsageWithVerifyTestBase +{ + public GeoCentroidNoResultsAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage) { } + + protected override Action> FluentAggregations => a => a + .GeoCentroid("centroid", gb => gb + .Field(p => p.LocationPoint) + ); + + protected override AggregationDictionary InitializerAggregations => + new GeoCentroidAggregation("centroid", Infer.Field(p => p.LocationPoint)); + + protected override Query QueryScope => new TermQuery(Infer.Field(p => p.Name)) { Value = "noresult" }; + + protected override object QueryScopeJson { get; } = new { term = new { name = new { value = "noresult" } } }; + + protected override void ExpectResponse(SearchResponse response) + { + response.ShouldBeValid(); + var centroid = response.Aggregations.GetGeoCentroid("centroid"); + centroid.Should().NotBeNull(); + centroid.Count.Should().Be(0); + } +} diff --git a/tests/Tests/Aggregations/Metric/GeoLineAggregationUsageTests.cs b/tests/Tests/Aggregations/Metric/GeoLineAggregationUsageTests.cs new file mode 100644 index 00000000000..7e6ea50ead0 --- /dev/null +++ b/tests/Tests/Aggregations/Metric/GeoLineAggregationUsageTests.cs @@ -0,0 +1,50 @@ +// 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 System; +using Elastic.Clients.Elasticsearch.Aggregations; +using Tests.Core.ManagedElasticsearch.Clusters; +using Tests.Domain; +using Tests.Core.Extensions; +using Tests.Framework.EndpointTests.TestState; + +namespace Tests.Aggregations.Metric; + +// TODO - Security setup for XPack cluster seems to fail in 8.x + +//public class GeoLineAggregationUsageTests : AggregationUsageWithVerifyTestBase +//{ +// public GeoLineAggregationUsageTests(XPackCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + +// protected override Action> FluentAggregations => a => a +// .GeoLine("line", d => d +// .Point(p => p.Field(f => f.LocationPoint)) +// .Sort(p => p.Field(f => f.StartedOn)) +// .IncludeSort() +// .Size(25)); + +// protected override AggregationDictionary InitializerAggregations => +// new GeoLineAggregation("line") +// { +// IncludeSort = true, +// Point = new GeoLinePoint { Field = Infer.Field(p => p.LocationPoint) }, +// Sort = new GeoLineSort { Field = Infer.Field(p => p.StartedOn) }, +// Size = 25 +// }; + +// protected override void ExpectResponse(SearchResponse response) +// { +// response.ShouldBeValid(); +// response.Aggregations.Count.Should().Be(1); + +// var geoLine = response.Aggregations.GetGeoLine("line"); +// geoLine.Should().NotBeNull(); +// geoLine.Type.Should().Be("Feature"); +// geoLine.Geometry.Type.Should().Be("linestring"); +// geoLine.Geometry.Coordinates.Should().NotBeEmpty(); + +// //geoLine.Properties.Complete.Should().BeFalse(); // Needs review in ES spec +// //geoLine.Properties.SortValues.Should().NotBeEmpty() // Needs review in ES spec +// } +//} diff --git a/tests/Tests/_VerifySnapshots/GeoBoundsAggregationUsageTests.VerifyDescriptorJson.verified.txt b/tests/Tests/_VerifySnapshots/GeoBoundsAggregationUsageTests.VerifyDescriptorJson.verified.txt new file mode 100644 index 00000000000..238c856bca4 --- /dev/null +++ b/tests/Tests/_VerifySnapshots/GeoBoundsAggregationUsageTests.VerifyDescriptorJson.verified.txt @@ -0,0 +1,18 @@ +{ + aggregations: { + viewport: { + geo_bounds: { + field: locationPoint, + wrap_longitude: true + } + } + }, + query: { + term: { + type: { + value: project + } + } + }, + size: 0 +} \ No newline at end of file diff --git a/tests/Tests/_VerifySnapshots/GeoBoundsAggregationUsageTests.VerifyInitializerJson.verified.txt b/tests/Tests/_VerifySnapshots/GeoBoundsAggregationUsageTests.VerifyInitializerJson.verified.txt new file mode 100644 index 00000000000..238c856bca4 --- /dev/null +++ b/tests/Tests/_VerifySnapshots/GeoBoundsAggregationUsageTests.VerifyInitializerJson.verified.txt @@ -0,0 +1,18 @@ +{ + aggregations: { + viewport: { + geo_bounds: { + field: locationPoint, + wrap_longitude: true + } + } + }, + query: { + term: { + type: { + value: project + } + } + }, + size: 0 +} \ No newline at end of file diff --git a/tests/Tests/_VerifySnapshots/GeoCentroidAggregationUsageTests.VerifyDescriptorJson.verified.txt b/tests/Tests/_VerifySnapshots/GeoCentroidAggregationUsageTests.VerifyDescriptorJson.verified.txt new file mode 100644 index 00000000000..a4552c7343a --- /dev/null +++ b/tests/Tests/_VerifySnapshots/GeoCentroidAggregationUsageTests.VerifyDescriptorJson.verified.txt @@ -0,0 +1,17 @@ +{ + aggregations: { + centroid: { + geo_centroid: { + field: locationPoint + } + } + }, + query: { + term: { + type: { + value: project + } + } + }, + size: 0 +} \ No newline at end of file diff --git a/tests/Tests/_VerifySnapshots/GeoCentroidAggregationUsageTests.VerifyInitializerJson.verified.txt b/tests/Tests/_VerifySnapshots/GeoCentroidAggregationUsageTests.VerifyInitializerJson.verified.txt new file mode 100644 index 00000000000..a4552c7343a --- /dev/null +++ b/tests/Tests/_VerifySnapshots/GeoCentroidAggregationUsageTests.VerifyInitializerJson.verified.txt @@ -0,0 +1,17 @@ +{ + aggregations: { + centroid: { + geo_centroid: { + field: locationPoint + } + } + }, + query: { + term: { + type: { + value: project + } + } + }, + size: 0 +} \ No newline at end of file diff --git a/tests/Tests/_VerifySnapshots/GeoCentroidNoResultsAggregationUsageTests.VerifyDescriptorJson.verified.txt b/tests/Tests/_VerifySnapshots/GeoCentroidNoResultsAggregationUsageTests.VerifyDescriptorJson.verified.txt new file mode 100644 index 00000000000..f7c471481bf --- /dev/null +++ b/tests/Tests/_VerifySnapshots/GeoCentroidNoResultsAggregationUsageTests.VerifyDescriptorJson.verified.txt @@ -0,0 +1,17 @@ +{ + aggregations: { + centroid: { + geo_centroid: { + field: locationPoint + } + } + }, + query: { + term: { + name: { + value: noresult + } + } + }, + size: 0 +} \ No newline at end of file diff --git a/tests/Tests/_VerifySnapshots/GeoCentroidNoResultsAggregationUsageTests.VerifyInitializerJson.verified.txt b/tests/Tests/_VerifySnapshots/GeoCentroidNoResultsAggregationUsageTests.VerifyInitializerJson.verified.txt new file mode 100644 index 00000000000..f7c471481bf --- /dev/null +++ b/tests/Tests/_VerifySnapshots/GeoCentroidNoResultsAggregationUsageTests.VerifyInitializerJson.verified.txt @@ -0,0 +1,17 @@ +{ + aggregations: { + centroid: { + geo_centroid: { + field: locationPoint + } + } + }, + query: { + term: { + name: { + value: noresult + } + } + }, + size: 0 +} \ No newline at end of file diff --git a/tests/Tests/_VerifySnapshots/GeoLineAggregationUsageTests.VerifyDescriptorJson.verified.txt b/tests/Tests/_VerifySnapshots/GeoLineAggregationUsageTests.VerifyDescriptorJson.verified.txt new file mode 100644 index 00000000000..81581674d16 --- /dev/null +++ b/tests/Tests/_VerifySnapshots/GeoLineAggregationUsageTests.VerifyDescriptorJson.verified.txt @@ -0,0 +1,24 @@ +{ + aggregations: { + line: { + geo_line: { + include_sort: true, + point: { + field: locationPoint + }, + size: 25, + sort: { + field: startedOn + } + } + } + }, + query: { + term: { + type: { + value: project + } + } + }, + size: 0 +} \ No newline at end of file diff --git a/tests/Tests/_VerifySnapshots/GeoLineAggregationUsageTests.VerifyInitializerJson.verified.txt b/tests/Tests/_VerifySnapshots/GeoLineAggregationUsageTests.VerifyInitializerJson.verified.txt new file mode 100644 index 00000000000..81581674d16 --- /dev/null +++ b/tests/Tests/_VerifySnapshots/GeoLineAggregationUsageTests.VerifyInitializerJson.verified.txt @@ -0,0 +1,24 @@ +{ + aggregations: { + line: { + geo_line: { + include_sort: true, + point: { + field: locationPoint + }, + size: 25, + sort: { + field: startedOn + } + } + } + }, + query: { + term: { + type: { + value: project + } + } + }, + size: 0 +} \ No newline at end of file diff --git a/tests/Tests/_VerifySnapshots/NestedGeoCentroidAggregationUsageTests.VerifyDescriptorJson.verified.txt b/tests/Tests/_VerifySnapshots/NestedGeoCentroidAggregationUsageTests.VerifyDescriptorJson.verified.txt new file mode 100644 index 00000000000..669c4940c18 --- /dev/null +++ b/tests/Tests/_VerifySnapshots/NestedGeoCentroidAggregationUsageTests.VerifyDescriptorJson.verified.txt @@ -0,0 +1,24 @@ +{ + aggregations: { + projects: { + aggregations: { + centroid: { + geo_centroid: { + field: locationPoint + } + } + }, + terms: { + field: name + } + } + }, + query: { + term: { + type: { + value: project + } + } + }, + size: 0 +} \ No newline at end of file diff --git a/tests/Tests/_VerifySnapshots/NestedGeoCentroidAggregationUsageTests.VerifyInitializerJson.verified.txt b/tests/Tests/_VerifySnapshots/NestedGeoCentroidAggregationUsageTests.VerifyInitializerJson.verified.txt new file mode 100644 index 00000000000..669c4940c18 --- /dev/null +++ b/tests/Tests/_VerifySnapshots/NestedGeoCentroidAggregationUsageTests.VerifyInitializerJson.verified.txt @@ -0,0 +1,24 @@ +{ + aggregations: { + projects: { + aggregations: { + centroid: { + geo_centroid: { + field: locationPoint + } + } + }, + terms: { + field: name + } + } + }, + query: { + term: { + type: { + value: project + } + } + }, + size: 0 +} \ No newline at end of file