diff --git a/src/Elastic.Clients.Elasticsearch/Types/Aggregations/AggregateDictionary.cs b/src/Elastic.Clients.Elasticsearch/Types/Aggregations/AggregateDictionary.cs index ed21392c4ea..03bb99058bd 100644 --- a/src/Elastic.Clients.Elasticsearch/Types/Aggregations/AggregateDictionary.cs +++ b/src/Elastic.Clients.Elasticsearch/Types/Aggregations/AggregateDictionary.cs @@ -49,35 +49,19 @@ public TermsAggregate GetTerms(string key) return null; } - Buckets> buckets = null; - switch (agg) { case EmptyTermsAggregate empty: return new TermsAggregate { - Buckets = new Buckets>(Array.Empty>()), + Buckets = Array.Empty>().ToReadOnlyCollection(), Meta = empty.Meta, DocCountErrorUpperBound = empty.DocCountErrorUpperBound, SumOtherDocCount = empty.SumOtherDocCount }; case StringTermsAggregate stringTerms: - stringTerms.Buckets.Match(a => - { - var dict = new Dictionary>(); - foreach (var item in a) - { - var key = item.Key; - var value = item.Value; - dict.Add(key, new TermsBucket(value.BackingDictionary) { DocCount = value.DocCount, DocCountError = value.DocCountError, Key = GetKeyFromBucketKey(value.Key), KeyAsString = value.Key }); - } - buckets = new(dict); - }, a => - { - buckets = new(a.Select(b => new TermsBucket(b.BackingDictionary) { DocCount = b.DocCount, DocCountError = b.DocCountError, Key = GetKeyFromBucketKey(b.Key), KeyAsString = b.Key }).ToReadOnlyCollection()); - }); - + var buckets = stringTerms.Buckets.Select(b => new TermsBucket(b.BackingDictionary) { DocCount = b.DocCount, DocCountError = b.DocCountError, Key = GetKeyFromBucketKey(b.Key), KeyAsString = b.Key }).ToReadOnlyCollection(); return new TermsAggregate { Buckets = buckets, @@ -87,48 +71,20 @@ public TermsAggregate GetTerms(string key) }; case DoubleTermsAggregate doubleTerms: - doubleTerms.Buckets.Match(a => - { - var dict = new Dictionary>(); - foreach (var item in a) - { - var key = item.Key; - var value = item.Value; - dict.Add(key, new TermsBucket(value.BackingDictionary) { DocCount = value.DocCount, DocCountError = value.DocCountError, Key = GetKeyFromBucketKey(value.Key), KeyAsString = value.KeyAsString }); - } - buckets = new(dict); - }, a => - { - buckets = new(a.Select(b => new TermsBucket(b.BackingDictionary) { DocCount = b.DocCount, DocCountError = b.DocCountError, Key = GetKeyFromBucketKey(b.Key), KeyAsString = b.KeyAsString }).ToReadOnlyCollection()); - }); - + var doubleTermsBuckets = doubleTerms.Buckets.Select(b => new TermsBucket(b.BackingDictionary) { DocCount = b.DocCount, DocCountError = b.DocCountError, Key = GetKeyFromBucketKey(b.Key), KeyAsString = b.KeyAsString }).ToReadOnlyCollection(); return new TermsAggregate { - Buckets = buckets, + Buckets = doubleTermsBuckets, Meta = doubleTerms.Meta, DocCountErrorUpperBound = doubleTerms.DocCountErrorUpperBound, SumOtherDocCount = doubleTerms.SumOtherDocCount }; case LongTermsAggregate longTerms: - longTerms.Buckets.Match(a => - { - var dict = new Dictionary>(); - foreach (var item in a) - { - var key = item.Key; - var value = item.Value; - dict.Add(key, new TermsBucket(value.BackingDictionary) { DocCount = value.DocCount, DocCountError = value.DocCountError, Key = GetKeyFromBucketKey(value.Key), KeyAsString = value.KeyAsString }); - } - buckets = new(dict); - }, a => - { - buckets = new(a.Select(b => new TermsBucket(b.BackingDictionary) { DocCount = b.DocCount, DocCountError = b.DocCountError, Key = GetKeyFromBucketKey(b.Key), KeyAsString = b.KeyAsString }).ToReadOnlyCollection()); - }); - + var longTermsBuckets = longTerms.Buckets.Select(b => new TermsBucket(b.BackingDictionary) { DocCount = b.DocCount, DocCountError = b.DocCountError, Key = GetKeyFromBucketKey(b.Key), KeyAsString = b.KeyAsString }).ToReadOnlyCollection(); return new TermsAggregate { - Buckets = buckets, + Buckets = longTermsBuckets, Meta = longTerms.Meta, DocCountErrorUpperBound = longTerms.DocCountErrorUpperBound, SumOtherDocCount = longTerms.SumOtherDocCount diff --git a/src/Elastic.Clients.Elasticsearch/Types/Aggregations/TermsAggregate.cs b/src/Elastic.Clients.Elasticsearch/Types/Aggregations/TermsAggregate.cs index a0642717d62..e411204472c 100644 --- a/src/Elastic.Clients.Elasticsearch/Types/Aggregations/TermsAggregate.cs +++ b/src/Elastic.Clients.Elasticsearch/Types/Aggregations/TermsAggregate.cs @@ -19,7 +19,7 @@ public sealed class TermsAggregate : IAggregate [JsonInclude] [JsonPropertyName("buckets")] - public Buckets> Buckets { get; init; } + public IReadOnlyCollection> Buckets { get; init; } [JsonInclude] [JsonPropertyName("meta")] diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AdjacencyMatrixAggregate.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AdjacencyMatrixAggregate.g.cs index e796df4cbb1..1c2c6ecf8dd 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AdjacencyMatrixAggregate.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AdjacencyMatrixAggregate.g.cs @@ -28,7 +28,7 @@ public sealed partial class AdjacencyMatrixAggregate : IAggregate { [JsonInclude] [JsonPropertyName("buckets")] - public Elastic.Clients.Elasticsearch.Aggregations.Buckets Buckets { get; init; } + public IReadOnlyCollection Buckets { get; init; } [JsonInclude] [JsonPropertyName("meta")] diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AutoDateHistogramAggregate.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AutoDateHistogramAggregate.g.cs index d9df4ae316f..012dacbf950 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AutoDateHistogramAggregate.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AutoDateHistogramAggregate.g.cs @@ -28,7 +28,7 @@ public sealed partial class AutoDateHistogramAggregate : IAggregate { [JsonInclude] [JsonPropertyName("buckets")] - public Elastic.Clients.Elasticsearch.Aggregations.Buckets Buckets { get; init; } + public IReadOnlyCollection Buckets { get; init; } [JsonInclude] [JsonPropertyName("interval")] diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregate.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregate.g.cs index 198effa27fe..62eb8272f36 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregate.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregate.g.cs @@ -32,7 +32,7 @@ public sealed partial class CompositeAggregate : IAggregate [JsonInclude] [JsonPropertyName("buckets")] - public Elastic.Clients.Elasticsearch.Aggregations.Buckets Buckets { get; init; } + public IReadOnlyCollection Buckets { get; init; } [JsonInclude] [JsonPropertyName("meta")] diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DateHistogramAggregate.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DateHistogramAggregate.g.cs index c9cf5eca82a..af168645a55 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DateHistogramAggregate.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DateHistogramAggregate.g.cs @@ -28,7 +28,7 @@ public sealed partial class DateHistogramAggregate : IAggregate { [JsonInclude] [JsonPropertyName("buckets")] - public Elastic.Clients.Elasticsearch.Aggregations.Buckets Buckets { get; init; } + public IReadOnlyCollection Buckets { get; init; } [JsonInclude] [JsonPropertyName("meta")] diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DateRangeAggregate.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DateRangeAggregate.g.cs index f7dcced0a04..564ae8a12c2 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DateRangeAggregate.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DateRangeAggregate.g.cs @@ -28,7 +28,7 @@ public sealed partial class DateRangeAggregate : IAggregate { [JsonInclude] [JsonPropertyName("buckets")] - public Elastic.Clients.Elasticsearch.Aggregations.Buckets Buckets { get; init; } + public IReadOnlyCollection Buckets { get; init; } [JsonInclude] [JsonPropertyName("meta")] diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DoubleTermsAggregate.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DoubleTermsAggregate.g.cs index 3f52b2650f0..02318caf277 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DoubleTermsAggregate.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DoubleTermsAggregate.g.cs @@ -28,7 +28,7 @@ public sealed partial class DoubleTermsAggregate : IAggregate { [JsonInclude] [JsonPropertyName("buckets")] - public Elastic.Clients.Elasticsearch.Aggregations.Buckets Buckets { get; init; } + public IReadOnlyCollection Buckets { get; init; } [JsonInclude] [JsonPropertyName("doc_count_error_upper_bound")] diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/FiltersAggregate.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/FiltersAggregate.g.cs index 858b77b0f0a..1251fbb3335 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/FiltersAggregate.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/FiltersAggregate.g.cs @@ -28,7 +28,7 @@ public sealed partial class FiltersAggregate : IAggregate { [JsonInclude] [JsonPropertyName("buckets")] - public Elastic.Clients.Elasticsearch.Aggregations.Buckets Buckets { get; init; } + public IReadOnlyCollection Buckets { get; init; } [JsonInclude] [JsonPropertyName("meta")] diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/HistogramAggregate.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/HistogramAggregate.g.cs index 33435a1d204..9bde84ad997 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/HistogramAggregate.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/HistogramAggregate.g.cs @@ -28,7 +28,7 @@ public sealed partial class HistogramAggregate : IAggregate { [JsonInclude] [JsonPropertyName("buckets")] - public Elastic.Clients.Elasticsearch.Aggregations.Buckets Buckets { get; init; } + public IReadOnlyCollection Buckets { get; init; } [JsonInclude] [JsonPropertyName("meta")] diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/IpRangeAggregate.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/IpRangeAggregate.g.cs index a34dd20cff2..c46adae4a0f 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/IpRangeAggregate.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/IpRangeAggregate.g.cs @@ -28,7 +28,7 @@ public sealed partial class IpRangeAggregate : IAggregate { [JsonInclude] [JsonPropertyName("buckets")] - public Elastic.Clients.Elasticsearch.Aggregations.Buckets Buckets { get; init; } + public IReadOnlyCollection Buckets { get; init; } [JsonInclude] [JsonPropertyName("meta")] diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/LongTermsAggregate.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/LongTermsAggregate.g.cs index eca5789faa0..4063b1848ab 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/LongTermsAggregate.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/LongTermsAggregate.g.cs @@ -28,7 +28,7 @@ public sealed partial class LongTermsAggregate : IAggregate { [JsonInclude] [JsonPropertyName("buckets")] - public Elastic.Clients.Elasticsearch.Aggregations.Buckets Buckets { get; init; } + public IReadOnlyCollection Buckets { get; init; } [JsonInclude] [JsonPropertyName("doc_count_error_upper_bound")] diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/MultiTermsAggregate.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/MultiTermsAggregate.g.cs index 166021709ff..f792f7c5214 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/MultiTermsAggregate.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/MultiTermsAggregate.g.cs @@ -28,7 +28,7 @@ public sealed partial class MultiTermsAggregate : IAggregate { [JsonInclude] [JsonPropertyName("buckets")] - public Elastic.Clients.Elasticsearch.Aggregations.Buckets Buckets { get; init; } + public IReadOnlyCollection Buckets { get; init; } [JsonInclude] [JsonPropertyName("doc_count_error_upper_bound")] diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/RangeAggregate.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/RangeAggregate.g.cs index 2f1520025d0..f9401a86f6a 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/RangeAggregate.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/RangeAggregate.g.cs @@ -28,7 +28,7 @@ public sealed partial class RangeAggregate : IAggregate { [JsonInclude] [JsonPropertyName("buckets")] - public Elastic.Clients.Elasticsearch.Aggregations.Buckets Buckets { get; init; } + public IReadOnlyCollection Buckets { get; init; } [JsonInclude] [JsonPropertyName("meta")] diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/StringTermsAggregate.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/StringTermsAggregate.g.cs index ed46bf85fdf..cab38faa90e 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/StringTermsAggregate.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/StringTermsAggregate.g.cs @@ -28,7 +28,7 @@ public sealed partial class StringTermsAggregate : IAggregate { [JsonInclude] [JsonPropertyName("buckets")] - public Elastic.Clients.Elasticsearch.Aggregations.Buckets Buckets { get; init; } + public IReadOnlyCollection Buckets { get; init; } [JsonInclude] [JsonPropertyName("doc_count_error_upper_bound")] diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/VariableWidthHistogramAggregate.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/VariableWidthHistogramAggregate.g.cs index d97c5a6d386..8ee93192fa9 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/VariableWidthHistogramAggregate.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/VariableWidthHistogramAggregate.g.cs @@ -28,7 +28,7 @@ public sealed partial class VariableWidthHistogramAggregate : IAggregate { [JsonInclude] [JsonPropertyName("buckets")] - public Elastic.Clients.Elasticsearch.Aggregations.Buckets Buckets { get; init; } + public IReadOnlyCollection Buckets { get; init; } [JsonInclude] [JsonPropertyName("meta")] diff --git a/tests/Tests/Aggregations/Bucket/TermsAggregationUsageTests.cs b/tests/Tests/Aggregations/Bucket/TermsAggregationUsageTests.cs index 472f6afef16..b1c4b221d63 100644 --- a/tests/Tests/Aggregations/Bucket/TermsAggregationUsageTests.cs +++ b/tests/Tests/Aggregations/Bucket/TermsAggregationUsageTests.cs @@ -97,7 +97,7 @@ protected override void ExpectResponse(SearchResponse response) states.SumOtherDocCount.Should().BeGreaterOrEqualTo(0); states.Buckets.Should().NotBeNull(); - var bucketsCollection = states.Buckets.Item2; + var bucketsCollection = states.Buckets; bucketsCollection.Count.Should().BeGreaterThan(0); foreach (var item in bucketsCollection) diff --git a/tests/Tests/Serialization/Aggregations/BucketSubAggregationSerializationTests.cs b/tests/Tests/Serialization/Aggregations/BucketSubAggregationSerializationTests.cs index b81a16bd44e..ca605db6b6f 100644 --- a/tests/Tests/Serialization/Aggregations/BucketSubAggregationSerializationTests.cs +++ b/tests/Tests/Serialization/Aggregations/BucketSubAggregationSerializationTests.cs @@ -20,7 +20,7 @@ public void DeserializeSubAggsForDateHistorgram() dateHistogramAgg.Should().NotBeNull(); - var bucketsCollection = dateHistogramAgg.Buckets.Item2; + var bucketsCollection = dateHistogramAgg.Buckets; bucketsCollection.Should().HaveCount(1); var dateBucket = bucketsCollection.First(); diff --git a/tests/Tests/Serialization/Aggregations/ChildrenAggregateSerializationTests.cs b/tests/Tests/Serialization/Aggregations/ChildrenAggregateSerializationTests.cs index d78914a38de..24f702561e0 100644 --- a/tests/Tests/Serialization/Aggregations/ChildrenAggregateSerializationTests.cs +++ b/tests/Tests/Serialization/Aggregations/ChildrenAggregateSerializationTests.cs @@ -16,10 +16,10 @@ public void DeserialisesCorrectly() var searchResponse = DeserializeJsonString>(json); var topTagsTermsAggregate = searchResponse.Aggregations.GetTerms("top-tags"); - var firstTopTagsBucket = topTagsTermsAggregate.Buckets.Item2.Single(); + var firstTopTagsBucket = topTagsTermsAggregate.Buckets.Single(); var childrenAggregate = firstTopTagsBucket.GetChildren("to-answers"); var topNamesAggregate = childrenAggregate.GetTerms("top-names"); - var firstTopNameBucket = topNamesAggregate.Buckets.Item2.First(); + var firstTopNameBucket = topNamesAggregate.Buckets.First(); firstTopNameBucket.Key.Should().Be("Sam"); } } diff --git a/tests/Tests/Serialization/Aggregations/TermsAggregateDeserializationTests.cs b/tests/Tests/Serialization/Aggregations/TermsAggregateDeserializationTests.cs index e999586f983..b2b97e92016 100644 --- a/tests/Tests/Serialization/Aggregations/TermsAggregateDeserializationTests.cs +++ b/tests/Tests/Serialization/Aggregations/TermsAggregateDeserializationTests.cs @@ -24,7 +24,7 @@ public void CanDeserialize_BasicStringTermsAggregate() var termsAgg = search.Aggregations.GetStringTerms("my-agg-name"); termsAgg.DocCountErrorUpperBound.Should().Be(10); termsAgg.SumOtherDocCount.Should().Be(200); - var bucketCollection = termsAgg.Buckets.Item2; + var bucketCollection = termsAgg.Buckets; bucketCollection.Should().HaveCount(2); var firstBucket = bucketCollection.First(); @@ -54,7 +54,7 @@ public void CanDeserialize_BasicLongTermsAggregate() termsAgg.DocCountErrorUpperBound.Should().Be(10); termsAgg.SumOtherDocCount.Should().Be(200); - var bucketCollection = termsAgg.Buckets.Item2; + var bucketCollection = termsAgg.Buckets; bucketCollection.Should().HaveCount(2); var firstBucket = bucketCollection.First(); @@ -86,7 +86,7 @@ public void CanDeserialize_BasicDoubleTermsAggregate() termsAgg.DocCountErrorUpperBound.Should().Be(10); termsAgg.SumOtherDocCount.Should().Be(200); - var bucketCollection = termsAgg.Buckets.Item2; + var bucketCollection = termsAgg.Buckets; bucketCollection.Should().HaveCount(2); var firstBucket = bucketCollection.First(); @@ -119,7 +119,7 @@ public void CanDeserialize_StringBased_MultiTermsAggregate() termsAgg.DocCountErrorUpperBound.Should().Be(10); termsAgg.SumOtherDocCount.Should().Be(200); - var bucketCollection = termsAgg.Buckets.Item2; + var bucketCollection = termsAgg.Buckets; var firstBucket = bucketCollection.First(); firstBucket.Key.Should().HaveCount(2); @@ -154,7 +154,7 @@ public void CanDeserialize_BasicDoubleTerms_AndAccessAsTermsAggregate() termsAgg.DocCountErrorUpperBound.Should().Be(10); termsAgg.SumOtherDocCount.Should().Be(200); - var bucketCollection = termsAgg.Buckets.Item2; + var bucketCollection = termsAgg.Buckets; bucketCollection.Should().HaveCount(2); @@ -201,7 +201,7 @@ public void CanDeserialize_TermsAggregate_WithSubAggregation() var response = DeserializeJsonString>(json); var termsAgg = response.Aggregations.GetTerms("my-agg-name"); - var avgAgg = termsAgg.Buckets.Item2.Single().GetAverage("my-sub-agg-name"); + var avgAgg = termsAgg.Buckets.Single().GetAverage("my-sub-agg-name"); avgAgg.Value.Should().Be(75.0); } }