diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Fluent/FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Fluent/FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource.g.cs new file mode 100644 index 00000000000..0bd0c614e59 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Fluent/FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource.g.cs @@ -0,0 +1,126 @@ +// 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 System; +using System.Linq; +using Elastic.Clients.Elasticsearch.Serialization; + +namespace Elastic.Clients.Elasticsearch.Fluent; + +public readonly partial struct FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource +{ + private readonly System.Collections.Generic.List> _items = new(); + + private System.Collections.Generic.ICollection> Value => _items; + + public FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource() + { + } + + public Elastic.Clients.Elasticsearch.Fluent.FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource Add(System.Collections.Generic.KeyValuePair value) + { + _items.Add(value); + return this; + } + + public Elastic.Clients.Elasticsearch.Fluent.FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource Add(params System.Collections.Generic.KeyValuePair[] values) + { + _items.AddRange(values); + return this; + } + + public Elastic.Clients.Elasticsearch.Fluent.FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource Add(string key, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource value) + { + _items.Add(new System.Collections.Generic.KeyValuePair(key, value)); + return this; + } + + public Elastic.Clients.Elasticsearch.Fluent.FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource Add(string key, System.Action> action) + { + _items.Add(new System.Collections.Generic.KeyValuePair(key, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSourceDescriptor.Build(action))); + return this; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + internal static System.Collections.Generic.ICollection> Build(System.Action>? action) + { + if (action is null) + { + return []; + } + + var builder = new Elastic.Clients.Elasticsearch.Fluent.FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource(); + action.Invoke(builder); + return builder.Value; + } +} + +public readonly partial struct FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource +{ + private readonly System.Collections.Generic.List> _items = new(); + + private System.Collections.Generic.ICollection> Value => _items; + + public FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource() + { + } + + public Elastic.Clients.Elasticsearch.Fluent.FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource Add(System.Collections.Generic.KeyValuePair value) + { + _items.Add(value); + return this; + } + + public Elastic.Clients.Elasticsearch.Fluent.FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource Add(params System.Collections.Generic.KeyValuePair[] values) + { + _items.AddRange(values); + return this; + } + + public Elastic.Clients.Elasticsearch.Fluent.FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource Add(string key, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource value) + { + _items.Add(new System.Collections.Generic.KeyValuePair(key, value)); + return this; + } + + public Elastic.Clients.Elasticsearch.Fluent.FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource Add(string key, System.Action action) + { + _items.Add(new System.Collections.Generic.KeyValuePair(key, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSourceDescriptor.Build(action))); + return this; + } + + public Elastic.Clients.Elasticsearch.Fluent.FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource Add(string key, System.Action> action) + { + _items.Add(new System.Collections.Generic.KeyValuePair(key, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSourceDescriptor.Build(action))); + return this; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + internal static System.Collections.Generic.ICollection> Build(System.Action? action) + { + if (action is null) + { + return []; + } + + var builder = new Elastic.Clients.Elasticsearch.Fluent.FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource(); + action.Invoke(builder); + return builder.Value; + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Fluent/FluentDictionaryOfStringCompositeAggregationSource.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Fluent/FluentDictionaryOfStringCompositeAggregationSource.g.cs deleted file mode 100644 index 17c81c90a6b..00000000000 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Fluent/FluentDictionaryOfStringCompositeAggregationSource.g.cs +++ /dev/null @@ -1,114 +0,0 @@ -// 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 System; -using System.Linq; -using Elastic.Clients.Elasticsearch.Serialization; - -namespace Elastic.Clients.Elasticsearch.Fluent; - -public readonly partial struct FluentDictionaryOfStringCompositeAggregationSource -{ - private readonly System.Collections.Generic.Dictionary _items = new(); - - private System.Collections.Generic.IDictionary Value => _items; - - public FluentDictionaryOfStringCompositeAggregationSource() - { - } - - public Elastic.Clients.Elasticsearch.Fluent.FluentDictionaryOfStringCompositeAggregationSource Add(string key, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource value) - { - _items.Add(key, value); - return this; - } - - public Elastic.Clients.Elasticsearch.Fluent.FluentDictionaryOfStringCompositeAggregationSource Add(string key) - { - _items.Add(key, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSourceDescriptor.Build(null)); - return this; - } - - public Elastic.Clients.Elasticsearch.Fluent.FluentDictionaryOfStringCompositeAggregationSource Add(string key, System.Action>? action) - { - _items.Add(key, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSourceDescriptor.Build(action)); - return this; - } - - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - internal static System.Collections.Generic.IDictionary Build(System.Action>? action) - { - if (action is null) - { - return new System.Collections.Generic.Dictionary(); - } - - var builder = new Elastic.Clients.Elasticsearch.Fluent.FluentDictionaryOfStringCompositeAggregationSource(); - action.Invoke(builder); - return builder.Value; - } -} - -public readonly partial struct FluentDictionaryOfStringCompositeAggregationSource -{ - private readonly System.Collections.Generic.Dictionary _items = new(); - - private System.Collections.Generic.IDictionary Value => _items; - - public FluentDictionaryOfStringCompositeAggregationSource() - { - } - - public Elastic.Clients.Elasticsearch.Fluent.FluentDictionaryOfStringCompositeAggregationSource Add(string key, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource value) - { - _items.Add(key, value); - return this; - } - - public Elastic.Clients.Elasticsearch.Fluent.FluentDictionaryOfStringCompositeAggregationSource Add(string key) - { - _items.Add(key, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSourceDescriptor.Build(null)); - return this; - } - - public Elastic.Clients.Elasticsearch.Fluent.FluentDictionaryOfStringCompositeAggregationSource Add(string key, System.Action? action) - { - _items.Add(key, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSourceDescriptor.Build(action)); - return this; - } - - public Elastic.Clients.Elasticsearch.Fluent.FluentDictionaryOfStringCompositeAggregationSource Add(string key, System.Action>? action) - { - _items.Add(key, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSourceDescriptor.Build(action)); - return this; - } - - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - internal static System.Collections.Generic.IDictionary Build(System.Action? action) - { - if (action is null) - { - return new System.Collections.Generic.Dictionary(); - } - - var builder = new Elastic.Clients.Elasticsearch.Fluent.FluentDictionaryOfStringCompositeAggregationSource(); - action.Invoke(builder); - return builder.Value; - } -} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregation.Converters.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregation.Converters.g.cs index 78a15fcb61e..94dad94a2fa 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregation.Converters.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregation.Converters.g.cs @@ -34,7 +34,7 @@ public override Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregation reader.ValidateToken(System.Text.Json.JsonTokenType.StartObject); LocalJsonValue?> propAfter = default; LocalJsonValue propSize = default; - LocalJsonValue>?> propSources = default; + LocalJsonValue>?> propSources = default; while (reader.Read() && reader.TokenType is System.Text.Json.JsonTokenType.PropertyName) { if (propAfter.TryReadProperty(ref reader, options, PropAfter, static System.Collections.Generic.IDictionary? (ref System.Text.Json.Utf8JsonReader r, System.Text.Json.JsonSerializerOptions o) => r.ReadDictionaryValue(o, null, null))) @@ -47,7 +47,7 @@ public override Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregation continue; } - if (propSources.TryReadProperty(ref reader, options, PropSources, static System.Collections.Generic.ICollection>? (ref System.Text.Json.Utf8JsonReader r, System.Text.Json.JsonSerializerOptions o) => r.ReadCollectionValue>(o, static System.Collections.Generic.IDictionary (ref System.Text.Json.Utf8JsonReader r, System.Text.Json.JsonSerializerOptions o) => r.ReadDictionaryValue(o, null, null)!))) + if (propSources.TryReadProperty(ref reader, options, PropSources, static System.Collections.Generic.ICollection>? (ref System.Text.Json.Utf8JsonReader r, System.Text.Json.JsonSerializerOptions o) => r.ReadCollectionValue>(o, static System.Collections.Generic.KeyValuePair (ref System.Text.Json.Utf8JsonReader r, System.Text.Json.JsonSerializerOptions o) => r.ReadKeyValuePairValue(o, null, null)))) { continue; } @@ -75,7 +75,7 @@ public override void Write(System.Text.Json.Utf8JsonWriter writer, Elastic.Clien writer.WriteStartObject(); writer.WriteProperty(options, PropAfter, value.After, null, static (System.Text.Json.Utf8JsonWriter w, System.Text.Json.JsonSerializerOptions o, System.Collections.Generic.IDictionary? v) => w.WriteDictionaryValue(o, v, null, null)); writer.WriteProperty(options, PropSize, value.Size, null, static (System.Text.Json.Utf8JsonWriter w, System.Text.Json.JsonSerializerOptions o, int? v) => w.WriteNullableValue(o, v)); - writer.WriteProperty(options, PropSources, value.Sources, null, static (System.Text.Json.Utf8JsonWriter w, System.Text.Json.JsonSerializerOptions o, System.Collections.Generic.ICollection>? v) => w.WriteCollectionValue>(o, v, static (System.Text.Json.Utf8JsonWriter w, System.Text.Json.JsonSerializerOptions o, System.Collections.Generic.IDictionary v) => w.WriteDictionaryValue(o, v, null, null))); + writer.WriteProperty(options, PropSources, value.Sources, null, static (System.Text.Json.Utf8JsonWriter w, System.Text.Json.JsonSerializerOptions o, System.Collections.Generic.ICollection>? v) => w.WriteCollectionValue>(o, v, static (System.Text.Json.Utf8JsonWriter w, System.Text.Json.JsonSerializerOptions o, System.Collections.Generic.KeyValuePair v) => w.WriteKeyValuePairValue(o, v, null, null))); writer.WriteEndObject(); } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregation.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregation.g.cs index c6aa0cf35b1..df81db7b9f5 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregation.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregation.g.cs @@ -62,7 +62,7 @@ internal CompositeAggregation(Elastic.Clients.Elasticsearch.Serialization.JsonCo /// Keys are returned in the order of the sources definition. /// /// - public System.Collections.Generic.ICollection>? Sources { get; set; } + public System.Collections.Generic.ICollection>? Sources { get; set; } } public readonly partial struct CompositeAggregationDescriptor @@ -148,7 +148,7 @@ public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor /// Keys are returned in the order of the sources definition. /// /// - public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor Sources(System.Collections.Generic.ICollection>? value) + public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor Sources(System.Collections.Generic.ICollection>? value) { Instance.Sources = value; return this; @@ -160,9 +160,9 @@ public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor /// Keys are returned in the order of the sources definition. /// /// - public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor Sources(params System.Collections.Generic.IDictionary[] values) + public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor Sources() { - Instance.Sources = [.. values]; + Instance.Sources = Elastic.Clients.Elasticsearch.Fluent.FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource.Build(null); return this; } @@ -172,15 +172,23 @@ public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor /// Keys are returned in the order of the sources definition. /// /// - public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor Sources(params System.Action>?[] actions) + public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor Sources(System.Action>? action) { - var items = new System.Collections.Generic.List>(); - foreach (var action in actions) - { - items.Add(Elastic.Clients.Elasticsearch.Fluent.FluentDictionaryOfStringCompositeAggregationSource.Build(action)); - } + Instance.Sources = Elastic.Clients.Elasticsearch.Fluent.FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource.Build(action); + return this; + } - Instance.Sources = items; + public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor AddSource(string key, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource value) + { + Instance.Sources ??= new System.Collections.Generic.List>(); + Instance.Sources.Add(new System.Collections.Generic.KeyValuePair(key, value)); + return this; + } + + public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor AddSource(string key, System.Action> action) + { + Instance.Sources ??= new System.Collections.Generic.List>(); + Instance.Sources.Add(new System.Collections.Generic.KeyValuePair(key, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSourceDescriptor.Build(action))); return this; } @@ -292,7 +300,7 @@ public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor /// Keys are returned in the order of the sources definition. /// /// - public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor Sources(System.Collections.Generic.ICollection>? value) + public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor Sources(System.Collections.Generic.ICollection>? value) { Instance.Sources = value; return this; @@ -304,9 +312,9 @@ public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor /// Keys are returned in the order of the sources definition. /// /// - public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor Sources(params System.Collections.Generic.IDictionary[] values) + public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor Sources() { - Instance.Sources = [.. values]; + Instance.Sources = Elastic.Clients.Elasticsearch.Fluent.FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource.Build(null); return this; } @@ -316,15 +324,9 @@ public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor /// Keys are returned in the order of the sources definition. /// /// - public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor Sources(params System.Action?[] actions) + public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor Sources(System.Action? action) { - var items = new System.Collections.Generic.List>(); - foreach (var action in actions) - { - items.Add(Elastic.Clients.Elasticsearch.Fluent.FluentDictionaryOfStringCompositeAggregationSource.Build(action)); - } - - Instance.Sources = items; + Instance.Sources = Elastic.Clients.Elasticsearch.Fluent.FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource.Build(action); return this; } @@ -334,15 +336,30 @@ public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor /// Keys are returned in the order of the sources definition. /// /// - public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor Sources(params System.Action>?[] actions) + public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor Sources(System.Action>? action) { - var items = new System.Collections.Generic.List>(); - foreach (var action in actions) - { - items.Add(Elastic.Clients.Elasticsearch.Fluent.FluentDictionaryOfStringCompositeAggregationSource.Build(action)); - } + Instance.Sources = Elastic.Clients.Elasticsearch.Fluent.FluentCollectionOfKeyValuePairOfStringCompositeAggregationSource.Build(action); + return this; + } + + public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor AddSource(string key, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource value) + { + Instance.Sources ??= new System.Collections.Generic.List>(); + Instance.Sources.Add(new System.Collections.Generic.KeyValuePair(key, value)); + return this; + } + + public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor AddSource(string key, System.Action action) + { + Instance.Sources ??= new System.Collections.Generic.List>(); + Instance.Sources.Add(new System.Collections.Generic.KeyValuePair(key, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSourceDescriptor.Build(action))); + return this; + } - Instance.Sources = items; + public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationDescriptor AddSource(string key, System.Action> action) + { + Instance.Sources ??= new System.Collections.Generic.List>(); + Instance.Sources.Add(new System.Collections.Generic.KeyValuePair(key, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSourceDescriptor.Build(action))); return this; } diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregationSource.Converters.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregationSource.Converters.g.cs index ece6288e156..4456be36c81 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregationSource.Converters.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregationSource.Converters.g.cs @@ -25,37 +25,47 @@ namespace Elastic.Clients.Elasticsearch.Aggregations.Json; public sealed partial class CompositeAggregationSourceConverter : System.Text.Json.Serialization.JsonConverter { - private static readonly System.Text.Json.JsonEncodedText PropDateHistogram = System.Text.Json.JsonEncodedText.Encode("date_histogram"); - private static readonly System.Text.Json.JsonEncodedText PropGeotileGrid = System.Text.Json.JsonEncodedText.Encode("geotile_grid"); - private static readonly System.Text.Json.JsonEncodedText PropHistogram = System.Text.Json.JsonEncodedText.Encode("histogram"); - private static readonly System.Text.Json.JsonEncodedText PropTerms = System.Text.Json.JsonEncodedText.Encode("terms"); + private static readonly System.Text.Json.JsonEncodedText VariantDateHistogram = System.Text.Json.JsonEncodedText.Encode("date_histogram"); + private static readonly System.Text.Json.JsonEncodedText VariantGeotileGrid = System.Text.Json.JsonEncodedText.Encode("geotile_grid"); + private static readonly System.Text.Json.JsonEncodedText VariantHistogram = System.Text.Json.JsonEncodedText.Encode("histogram"); + private static readonly System.Text.Json.JsonEncodedText VariantTerms = System.Text.Json.JsonEncodedText.Encode("terms"); public override Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) { reader.ValidateToken(System.Text.Json.JsonTokenType.StartObject); - LocalJsonValue propDateHistogram = default; - LocalJsonValue propGeotileGrid = default; - LocalJsonValue propHistogram = default; - LocalJsonValue propTerms = default; + string? variantType = null; + object? variant = null; while (reader.Read() && reader.TokenType is System.Text.Json.JsonTokenType.PropertyName) { - if (propDateHistogram.TryReadProperty(ref reader, options, PropDateHistogram, null)) + if (reader.ValueTextEquals(VariantDateHistogram)) { + variantType = VariantDateHistogram.Value; + reader.Read(); + variant = reader.ReadValue(options, null); continue; } - if (propGeotileGrid.TryReadProperty(ref reader, options, PropGeotileGrid, null)) + if (reader.ValueTextEquals(VariantGeotileGrid)) { + variantType = VariantGeotileGrid.Value; + reader.Read(); + variant = reader.ReadValue(options, null); continue; } - if (propHistogram.TryReadProperty(ref reader, options, PropHistogram, null)) + if (reader.ValueTextEquals(VariantHistogram)) { + variantType = VariantHistogram.Value; + reader.Read(); + variant = reader.ReadValue(options, null); continue; } - if (propTerms.TryReadProperty(ref reader, options, PropTerms, null)) + if (reader.ValueTextEquals(VariantTerms)) { + variantType = VariantTerms.Value; + reader.Read(); + variant = reader.ReadValue(options, null); continue; } @@ -71,20 +81,34 @@ public override Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationS reader.ValidateToken(System.Text.Json.JsonTokenType.EndObject); return new Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource(Elastic.Clients.Elasticsearch.Serialization.JsonConstructorSentinel.Instance) { - DateHistogram = propDateHistogram.Value, - GeotileGrid = propGeotileGrid.Value, - Histogram = propHistogram.Value, - Terms = propTerms.Value + VariantType = variantType, + Variant = variant }; } public override void Write(System.Text.Json.Utf8JsonWriter writer, Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource value, System.Text.Json.JsonSerializerOptions options) { writer.WriteStartObject(); - writer.WriteProperty(options, PropDateHistogram, value.DateHistogram, null, null); - writer.WriteProperty(options, PropGeotileGrid, value.GeotileGrid, null, null); - writer.WriteProperty(options, PropHistogram, value.Histogram, null, null); - writer.WriteProperty(options, PropTerms, value.Terms, null, null); + switch (value.VariantType) + { + case null: + break; + case "date_histogram": + writer.WriteProperty(options, value.VariantType, (Elastic.Clients.Elasticsearch.Aggregations.CompositeDateHistogramAggregation)value.Variant, null, null); + break; + case "geotile_grid": + writer.WriteProperty(options, value.VariantType, (Elastic.Clients.Elasticsearch.Aggregations.CompositeGeoTileGridAggregation)value.Variant, null, null); + break; + case "histogram": + writer.WriteProperty(options, value.VariantType, (Elastic.Clients.Elasticsearch.Aggregations.CompositeHistogramAggregation)value.Variant, null, null); + break; + case "terms": + writer.WriteProperty(options, value.VariantType, (Elastic.Clients.Elasticsearch.Aggregations.CompositeTermsAggregation)value.Variant, null, null); + break; + default: + throw new System.Text.Json.JsonException($"Variant '{value.VariantType}' is not supported for type '{nameof(Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource)}'."); + } + writer.WriteEndObject(); } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregationSource.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregationSource.g.cs index 561f1205cea..4e259268560 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregationSource.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregationSource.g.cs @@ -26,6 +26,8 @@ namespace Elastic.Clients.Elasticsearch.Aggregations; [System.Text.Json.Serialization.JsonConverter(typeof(Elastic.Clients.Elasticsearch.Aggregations.Json.CompositeAggregationSourceConverter))] public sealed partial class CompositeAggregationSource { + internal string? VariantType { get; set; } + internal object? Variant { get; set; } #if NET7_0_OR_GREATER public CompositeAggregationSource() { @@ -47,28 +49,51 @@ internal CompositeAggregationSource(Elastic.Clients.Elasticsearch.Serialization. /// A date histogram aggregation. /// /// - public Elastic.Clients.Elasticsearch.Aggregations.CompositeDateHistogramAggregation? DateHistogram { get; set; } + public Elastic.Clients.Elasticsearch.Aggregations.CompositeDateHistogramAggregation? DateHistogram { get => GetVariant("date_histogram"); set => SetVariant("date_histogram", value); } /// /// /// A geotile grid aggregation. /// /// - public Elastic.Clients.Elasticsearch.Aggregations.CompositeGeoTileGridAggregation? GeotileGrid { get; set; } + public Elastic.Clients.Elasticsearch.Aggregations.CompositeGeoTileGridAggregation? GeotileGrid { get => GetVariant("geotile_grid"); set => SetVariant("geotile_grid", value); } /// /// /// A histogram aggregation. /// /// - public Elastic.Clients.Elasticsearch.Aggregations.CompositeHistogramAggregation? Histogram { get; set; } + public Elastic.Clients.Elasticsearch.Aggregations.CompositeHistogramAggregation? Histogram { get => GetVariant("histogram"); set => SetVariant("histogram", value); } /// /// /// A terms aggregation. /// /// - public Elastic.Clients.Elasticsearch.Aggregations.CompositeTermsAggregation? Terms { get; set; } + public Elastic.Clients.Elasticsearch.Aggregations.CompositeTermsAggregation? Terms { get => GetVariant("terms"); set => SetVariant("terms", value); } + + public static implicit operator Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource(Elastic.Clients.Elasticsearch.Aggregations.CompositeDateHistogramAggregation value) => new Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource { DateHistogram = value }; + public static implicit operator Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource(Elastic.Clients.Elasticsearch.Aggregations.CompositeGeoTileGridAggregation value) => new Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource { GeotileGrid = value }; + public static implicit operator Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource(Elastic.Clients.Elasticsearch.Aggregations.CompositeHistogramAggregation value) => new Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource { Histogram = value }; + public static implicit operator Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource(Elastic.Clients.Elasticsearch.Aggregations.CompositeTermsAggregation value) => new Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource { Terms = value }; + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private T? GetVariant(string type) + { + if (string.Equals(VariantType, type, System.StringComparison.Ordinal) && Variant is T result) + { + return result; + } + + return default; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private void SetVariant(string type, T? value) + { + VariantType = type; + Variant = value; + } } public readonly partial struct CompositeAggregationSourceDescriptor @@ -212,13 +237,8 @@ public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSourceDesc } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - internal static Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource Build(System.Action>? action) + internal static Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource Build(System.Action> action) { - if (action is null) - { - return new Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource(Elastic.Clients.Elasticsearch.Serialization.JsonConstructorSentinel.Instance); - } - var builder = new Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSourceDescriptor(new Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource(Elastic.Clients.Elasticsearch.Serialization.JsonConstructorSentinel.Instance)); action.Invoke(builder); return builder.Instance; @@ -410,13 +430,8 @@ public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSourceDesc } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - internal static Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource Build(System.Action? action) + internal static Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource Build(System.Action action) { - if (action is null) - { - return new Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource(Elastic.Clients.Elasticsearch.Serialization.JsonConstructorSentinel.Instance); - } - var builder = new Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSourceDescriptor(new Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregationSource(Elastic.Clients.Elasticsearch.Serialization.JsonConstructorSentinel.Instance)); action.Invoke(builder); return builder.Instance;