From 1881229452daf3f435c13414a7b85a62a7a6e5ec Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Tue, 26 Apr 2022 14:47:21 +0100 Subject: [PATCH] Regenerated buckets with support for sub-aggs (#6375) * Regenerated buckets with support for sub-aggs * Fix license header --- .../AggregateDictionaryConverter.cs | 861 +++++++++--------- .../Aggregations/AdjacencyMatrixBucket.g.cs | 48 +- .../Aggregations/AggregateDictionary.g.cs | 94 +- .../Types/Aggregations/CompositeBucket.g.cs | 56 +- .../Aggregations/DateHistogramBucket.g.cs | 63 +- .../Types/Aggregations/DoubleTermsBucket.g.cs | 74 +- .../Types/Aggregations/FiltersBucket.g.cs | 48 +- .../Types/Aggregations/HistogramBucket.g.cs | 63 +- .../Types/Aggregations/IpRangeBucket.g.cs | 63 +- .../Types/Aggregations/LongTermsBucket.g.cs | 74 +- .../Types/Aggregations/MultiTermsBucket.g.cs | 70 +- .../Types/Aggregations/RangeBucket.g.cs | 84 +- .../Types/Aggregations/StringTermsBucket.g.cs | 67 +- .../VariableWidthHistogramBucket.g.cs | 91 +- src/Playground/Program.cs | 233 ++++- .../Aggregations/AggregationMetaUsageTests.cs | 2 +- .../DateHistogramAggregationUsageTests.cs | 2 +- .../Metric/BoxplotAggregationUsageTests.cs | 2 +- .../CardinalityAggregationUsageTests.cs | 2 +- .../ExtendedStatsAggregationUsageTests.cs | 2 +- .../Metric/MaxAggregationUsageTests.cs | 2 +- ...nAbsoluteDeviationAggregationUsageTests.cs | 2 +- .../Metric/MinAggregationUsageTests.cs | 2 +- .../Metric/StatsAggregationUsageTests.cs | 2 +- .../StringStatsAggregationUsageTests.cs | 2 +- ...tsWithDistributionAggregationUsageTests.cs | 2 +- .../Metric/SumAggregationUsageTests.cs | 2 +- .../Metric/ValueCountAggregationUsageTests.cs | 2 +- .../WeightedAverageAggregationUsageTests.cs | 2 +- .../BoxplotAggregateDeserializationTests.cs | 2 +- .../BucketSubAggregationSerializationTests.cs | 36 + ...ardinalityAggregateDeserializationTests.cs | 2 +- ...endedStatsAggregateDeserializationTests.cs | 2 +- .../SumAggregateDeserializationTests.cs | 4 +- .../TermsAggregateDeserializationTests.cs | 8 +- v7 | 1 + 36 files changed, 1523 insertions(+), 549 deletions(-) create mode 100644 tests/Tests/Serialization/Aggregations/BucketSubAggregationSerializationTests.cs create mode 160000 v7 diff --git a/src/Elastic.Clients.Elasticsearch/Types/Aggregations/AggregateDictionaryConverter.cs b/src/Elastic.Clients.Elasticsearch/Types/Aggregations/AggregateDictionaryConverter.cs index ef6a3fb662f..560d19a2e6d 100644 --- a/src/Elastic.Clients.Elasticsearch/Types/Aggregations/AggregateDictionaryConverter.cs +++ b/src/Elastic.Clients.Elasticsearch/Types/Aggregations/AggregateDictionaryConverter.cs @@ -27,441 +27,446 @@ internal sealed class AggregateDictionaryConverter : JsonConverter(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "auto_date_histogram": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "categorize_text": - throw new Exception("The aggregate in response is not yet supported"); - - case "children": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "composite": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "date_histogram": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "date_range": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "diversified_sampler": - throw new Exception("The aggregate in response is not yet supported"); - - case "filter": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "filters": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - //case "geo_distance": - // { - // var agg = JsonSerializer.Deserialize(ref reader, options); - // dictionary.Add(nameParts[1], agg); - // break; - // } - - //case "geohash_grid": - // { - // var agg = JsonSerializer.Deserialize(ref reader, options); - // dictionary.Add(nameParts[1], agg); - // break; - // } - - //case "geotile_grid": - // { - // var agg = JsonSerializer.Deserialize(ref reader, options); - // dictionary.Add(nameParts[1], agg); - // break; - // } - - case "global": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "histogram": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "ip_range": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "missing": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "multi_terms": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "nested": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "parent": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "range": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "rare_terms": - throw new Exception("The aggregate in response is not yet supported"); - - case "reverse_nested": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "sampler": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "significant_terms": - throw new Exception("The aggregate in response is not yet supported"); - - case "significant_text": - throw new Exception("The aggregate in response is not yet supported"); - - case "variable_width_histogram": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "avg": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "boxplot": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "cardinality": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "extended_stats": - { - 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 "matrix_stats": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "max": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "median_absolute_deviation": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "min": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "percentile_ranks": - throw new Exception("The aggregate in response is not yet supported."); - - case "tdigest_percentile_ranks": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "percentiles": - throw new Exception("The aggregate in response is not yet supported."); - - case "rate": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "scripted_metric": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "stats": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "string_stats": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "sum": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "t_test": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "top_hits": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "top_metrics": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "value_count": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "weighted_avg": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "avg_bucket": - throw new Exception("The aggregate in response is not yet supported."); - case "bucket_script": - throw new Exception("The aggregate in response is not yet supported."); - case "bucket_count_ks_test": - throw new Exception("The aggregate in response is not yet supported."); - case "bucket_correlation": - throw new Exception("The aggregate in response is not yet supported."); - case "bucket_selector": - throw new Exception("The aggregate in response is not yet supported."); - case "bucket_sort": - throw new Exception("The aggregate in response is not yet supported."); - - case "cumulative_cardinality": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "cumulative_sum": - throw new Exception("The aggregate in response is not yet supported."); - - case "derivative": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } - - case "extended_stats_bucket": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } + ReadAggregate(ref reader, options, dictionary, name); + } - case "inference": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } + return new AggregateDictionary(dictionary); + } - case "max_bucket": - throw new Exception("The aggregate in response is not yet supported."); - case "min_bucket": - throw new Exception("The aggregate in response is not yet supported."); - case "moving_avg": - throw new Exception("The aggregate in response is not yet supported."); - case "moving_fn": - throw new Exception("The aggregate in response is not yet supported."); - case "moving_percentiles": - throw new Exception("The aggregate in response is not yet supported."); - case "normalize": - throw new Exception("The aggregate in response is not yet supported."); - - case "percentiles_bucket": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } + public static void ReadAggregate(ref Utf8JsonReader reader, JsonSerializerOptions options, Dictionary dictionary, string name) + { + var nameParts = name.Split('#'); - case "serial_diff": - throw new Exception("The aggregate in response is not yet supported."); + if (nameParts.Length != 2) + throw new JsonException($"Unable to parse typed-key from aggregation name '{name}'"); - case "stats_bucket": - { - var agg = JsonSerializer.Deserialize(ref reader, options); - dictionary.Add(nameParts[1], agg); - break; - } + // Bucket-based Aggregates - case "sum_bucket": - throw new Exception("The aggregate in response is not yet supported."); + var aggregateName = nameParts[0]; - default: - throw new Exception("The aggregate in response is not yet supported."); - } + switch (aggregateName) + { + case "terms": + case "sterms": + case "lterms": + { + if (TermsAggregateSerializationHelper.TryDeserialiseTermsAggregate(ref reader, options, out var agg)) + { + dictionary.Add(nameParts[1], agg); + } + + break; + } + + case "adjacency_matrix": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "auto_date_histogram": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "categorize_text": + throw new Exception("The aggregate in response is not yet supported"); + + case "children": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "composite": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "date_histogram": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "date_range": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "diversified_sampler": + throw new Exception("The aggregate in response is not yet supported"); + + case "filter": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "filters": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + //case "geo_distance": + // { + // var agg = JsonSerializer.Deserialize(ref reader, options); + // dictionary.Add(nameParts[1], agg); + // break; + // } + + //case "geohash_grid": + // { + // var agg = JsonSerializer.Deserialize(ref reader, options); + // dictionary.Add(nameParts[1], agg); + // break; + // } + + //case "geotile_grid": + // { + // var agg = JsonSerializer.Deserialize(ref reader, options); + // dictionary.Add(nameParts[1], agg); + // break; + // } + + case "global": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "histogram": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "ip_range": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "missing": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "multi_terms": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "nested": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "parent": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "range": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "rare_terms": + throw new Exception("The aggregate in response is not yet supported"); + + case "reverse_nested": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "sampler": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "significant_terms": + throw new Exception("The aggregate in response is not yet supported"); + + case "significant_text": + throw new Exception("The aggregate in response is not yet supported"); + + case "variable_width_histogram": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "avg": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "boxplot": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "cardinality": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "extended_stats": + { + 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 "matrix_stats": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "max": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "median_absolute_deviation": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "min": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "percentile_ranks": + throw new Exception("The aggregate in response is not yet supported."); + + case "tdigest_percentile_ranks": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "percentiles": + throw new Exception("The aggregate in response is not yet supported."); + + case "rate": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "scripted_metric": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "stats": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "string_stats": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "sum": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "t_test": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "top_hits": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "top_metrics": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "value_count": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "weighted_avg": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "avg_bucket": + throw new Exception("The aggregate in response is not yet supported."); + case "bucket_script": + throw new Exception("The aggregate in response is not yet supported."); + case "bucket_count_ks_test": + throw new Exception("The aggregate in response is not yet supported."); + case "bucket_correlation": + throw new Exception("The aggregate in response is not yet supported."); + case "bucket_selector": + throw new Exception("The aggregate in response is not yet supported."); + case "bucket_sort": + throw new Exception("The aggregate in response is not yet supported."); + + case "cumulative_cardinality": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "cumulative_sum": + throw new Exception("The aggregate in response is not yet supported."); + + case "derivative": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "extended_stats_bucket": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "inference": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "max_bucket": + throw new Exception("The aggregate in response is not yet supported."); + case "min_bucket": + throw new Exception("The aggregate in response is not yet supported."); + case "moving_avg": + throw new Exception("The aggregate in response is not yet supported."); + case "moving_fn": + throw new Exception("The aggregate in response is not yet supported."); + case "moving_percentiles": + throw new Exception("The aggregate in response is not yet supported."); + case "normalize": + throw new Exception("The aggregate in response is not yet supported."); + + case "percentiles_bucket": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "serial_diff": + throw new Exception("The aggregate in response is not yet supported."); + + case "stats_bucket": + { + var agg = JsonSerializer.Deserialize(ref reader, options); + dictionary.Add(nameParts[1], agg); + break; + } + + case "sum_bucket": + throw new Exception("The aggregate in response is not yet supported."); + + default: + throw new Exception("The aggregate in response is not yet supported."); } - - return new AggregateDictionary(dictionary); } public override void Write(Utf8JsonWriter writer, AggregateDictionary value, JsonSerializerOptions options) => throw new NotImplementedException(); diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AdjacencyMatrixBucket.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AdjacencyMatrixBucket.g.cs index 8154b920f44..1f6788a3dba 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AdjacencyMatrixBucket.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AdjacencyMatrixBucket.g.cs @@ -24,7 +24,53 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Aggregations { - public partial class AdjacencyMatrixBucket : MultiBucketBase + [JsonConverter(typeof(AdjacencyMatrixBucketConverter))] + public sealed partial class AdjacencyMatrixBucket : AggregateDictionary { + public AdjacencyMatrixBucket(IReadOnlyDictionary backingDictionary) : base(backingDictionary) + { + } + + [JsonInclude] + [JsonPropertyName("doc_count")] + public long DocCount { get; init; } + } + + internal sealed class AdjacencyMatrixBucketConverter : JsonConverter + { + public override AdjacencyMatrixBucket? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}."); + var subAggs = new Dictionary(); // TODO - Optimise this and only create if we need it. + long docCount = default; + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + break; + if (reader.TokenType != JsonTokenType.PropertyName) + throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}."); + var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those + reader.Read(); + if (name.Equals("doc_count", StringComparison.Ordinal)) + { + docCount = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Contains("#")) + { + AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name); + continue; + } + + throw new JsonException("Unknown property read from JSON."); + } + + return new AdjacencyMatrixBucket(subAggs) + { DocCount = docCount }; + } + + public override void Write(Utf8JsonWriter writer, AdjacencyMatrixBucket value, JsonSerializerOptions options) => throw new NotImplementedException(); } } \ No newline at end of file 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 27c47ee2f19..e2c3827b0aa 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AggregateDictionary.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AggregateDictionary.g.cs @@ -31,53 +31,53 @@ public AggregateDictionary(IReadOnlyDictionary backingDic { } - public Elastic.Clients.Elasticsearch.Aggregations.CardinalityAggregate? Cardinality(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.TDigestPercentileRanksAggregate? TDigestPercentileRanks(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.PercentilesBucketAggregate? PercentilesBucket(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.MedianAbsoluteDeviationAggregate? MedianAbsoluteDeviation(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.MinAggregate? Min(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.MaxAggregate? Max(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.SumAggregate? Sum(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.AvgAggregate? Avg(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.WeightedAvgAggregate? WeightedAvg(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.ValueCountAggregate? ValueCount(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.DerivativeAggregate? Derivative(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.StatsAggregate? Stats(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.StatsBucketAggregate? StatsBucket(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.ExtendedStatsAggregate? ExtendedStats(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.ExtendedStatsBucketAggregate? ExtendedStatsBucket(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.HistogramAggregate? Histogram(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.DateHistogramAggregate? DateHistogram(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.AutoDateHistogramAggregate? AutoDateHistogram(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.VariableWidthHistogramAggregate? VariableWidthHistogram(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.StringTermsAggregate? StringTerms(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.LongTermsAggregate? LongTerms(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.DoubleTermsAggregate? DoubleTerms(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.MultiTermsAggregate? MultiTerms(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.MissingAggregate? Missing(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.NestedAggregate? Nested(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.ReverseNestedAggregate? ReverseNested(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.GlobalAggregate? Global(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.FilterAggregate? Filter(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.ChildrenAggregate? Children(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.ParentAggregate? Parent(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.SamplerAggregate? Sampler(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.RangeAggregate? Range(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.DateRangeAggregate? DateRange(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.IpRangeAggregate? IpRange(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.FiltersAggregate? Filters(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.AdjacencyMatrixAggregate? AdjacencyMatrix(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregate? Composite(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.ScriptedMetricAggregate? ScriptedMetric(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.TopHitsAggregate? TopHits(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.InferenceAggregate? Inference(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.StringStatsAggregate? StringStats(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.BoxPlotAggregate? BoxPlot(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.TopMetricsAggregate? TopMetrics(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.TTestAggregate? TTest(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.RateAggregate? Rate(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.CumulativeCardinalityAggregate? CumulativeCardinality(string key) => TryGet(key); - public Elastic.Clients.Elasticsearch.Aggregations.MatrixStatsAggregate? MatrixStats(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.CardinalityAggregate? GetCardinality(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.TDigestPercentileRanksAggregate? GetTDigestPercentileRanks(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.PercentilesBucketAggregate? GetPercentilesBucket(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.MedianAbsoluteDeviationAggregate? GetMedianAbsoluteDeviation(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.MinAggregate? GetMin(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.MaxAggregate? GetMax(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.SumAggregate? GetSum(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.AvgAggregate? GetAvg(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.WeightedAvgAggregate? GetWeightedAvg(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.ValueCountAggregate? GetValueCount(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.DerivativeAggregate? GetDerivative(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.StatsAggregate? GetStats(string key) => TryGet(key); + 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.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); + public Elastic.Clients.Elasticsearch.Aggregations.VariableWidthHistogramAggregate? GetVariableWidthHistogram(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.StringTermsAggregate? GetStringTerms(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.LongTermsAggregate? GetLongTerms(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.DoubleTermsAggregate? GetDoubleTerms(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.MultiTermsAggregate? GetMultiTerms(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.MissingAggregate? GetMissing(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.NestedAggregate? GetNested(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.ReverseNestedAggregate? GetReverseNested(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.GlobalAggregate? GetGlobal(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.FilterAggregate? GetFilter(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.ChildrenAggregate? GetChildren(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.ParentAggregate? GetParent(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.SamplerAggregate? GetSampler(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.RangeAggregate? GetRange(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.DateRangeAggregate? GetDateRange(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.IpRangeAggregate? GetIpRange(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.FiltersAggregate? GetFilters(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.AdjacencyMatrixAggregate? GetAdjacencyMatrix(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.CompositeAggregate? GetComposite(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.ScriptedMetricAggregate? GetScriptedMetric(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.TopHitsAggregate? GetTopHits(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.InferenceAggregate? GetInference(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.StringStatsAggregate? GetStringStats(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.BoxPlotAggregate? GetBoxPlot(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.TopMetricsAggregate? GetTopMetrics(string key) => TryGet(key); + public Elastic.Clients.Elasticsearch.Aggregations.TTestAggregate? GetTTest(string key) => TryGet(key); + 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); private TAggregate TryGet(string key) where TAggregate : AggregateBase => BackingDictionary.TryGetValue(key, out var agg) ? agg as TAggregate : null; } diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeBucket.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeBucket.g.cs index 71499661f96..c7ee20c441b 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeBucket.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeBucket.g.cs @@ -24,10 +24,64 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Aggregations { - public partial class CompositeBucket : MultiBucketBase + [JsonConverter(typeof(CompositeBucketConverter))] + public sealed partial class CompositeBucket : AggregateDictionary { + public CompositeBucket(IReadOnlyDictionary backingDictionary) : base(backingDictionary) + { + } + + [JsonInclude] + [JsonPropertyName("doc_count")] + public long DocCount { get; init; } + [JsonInclude] [JsonPropertyName("key")] public Dictionary Key { get; init; } } + + internal sealed class CompositeBucketConverter : JsonConverter + { + public override CompositeBucket? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}."); + var subAggs = new Dictionary(); // TODO - Optimise this and only create if we need it. + long docCount = default; + Dictionary key = default; + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + break; + if (reader.TokenType != JsonTokenType.PropertyName) + throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}."); + var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those + reader.Read(); + if (name.Equals("doc_count", StringComparison.Ordinal)) + { + docCount = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("key", StringComparison.Ordinal)) + { + key = JsonSerializer.Deserialize>(ref reader, options); + continue; + } + + if (name.Contains("#")) + { + AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name); + continue; + } + + throw new JsonException("Unknown property read from JSON."); + } + + return new CompositeBucket(subAggs) + { DocCount = docCount, Key = key }; + } + + public override void Write(Utf8JsonWriter writer, CompositeBucket value, JsonSerializerOptions options) => throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DateHistogramBucket.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DateHistogramBucket.g.cs index fd35d3b1679..133428dfe61 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DateHistogramBucket.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DateHistogramBucket.g.cs @@ -24,8 +24,17 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Aggregations { - public partial class DateHistogramBucket : MultiBucketBase + [JsonConverter(typeof(DateHistogramBucketConverter))] + public sealed partial class DateHistogramBucket : AggregateDictionary { + public DateHistogramBucket(IReadOnlyDictionary backingDictionary) : base(backingDictionary) + { + } + + [JsonInclude] + [JsonPropertyName("doc_count")] + public long DocCount { get; init; } + [JsonInclude] [JsonPropertyName("key")] public Elastic.Clients.Elasticsearch.EpochMillis Key { get; init; } @@ -34,4 +43,56 @@ public partial class DateHistogramBucket : MultiBucketBase [JsonPropertyName("key_as_string")] public string? KeyAsString { get; init; } } + + internal sealed class DateHistogramBucketConverter : JsonConverter + { + public override DateHistogramBucket? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}."); + var subAggs = new Dictionary(); // TODO - Optimise this and only create if we need it. + long docCount = default; + Elastic.Clients.Elasticsearch.EpochMillis key = default; + string? keyAsString = default; + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + break; + if (reader.TokenType != JsonTokenType.PropertyName) + throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}."); + var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those + reader.Read(); + if (name.Equals("doc_count", StringComparison.Ordinal)) + { + docCount = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("key", StringComparison.Ordinal)) + { + key = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("key_as_string", StringComparison.Ordinal)) + { + keyAsString = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Contains("#")) + { + AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name); + continue; + } + + throw new JsonException("Unknown property read from JSON."); + } + + return new DateHistogramBucket(subAggs) + { DocCount = docCount, Key = key, KeyAsString = keyAsString }; + } + + public override void Write(Utf8JsonWriter writer, DateHistogramBucket value, JsonSerializerOptions options) => throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DoubleTermsBucket.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DoubleTermsBucket.g.cs index ea721b7de28..6eab2009bc8 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DoubleTermsBucket.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DoubleTermsBucket.g.cs @@ -24,8 +24,21 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Aggregations { - public partial class DoubleTermsBucket : TermsBucketBase + [JsonConverter(typeof(DoubleTermsBucketConverter))] + public sealed partial class DoubleTermsBucket : AggregateDictionary { + public DoubleTermsBucket(IReadOnlyDictionary backingDictionary) : base(backingDictionary) + { + } + + [JsonInclude] + [JsonPropertyName("doc_count")] + public long DocCount { get; init; } + + [JsonInclude] + [JsonPropertyName("doc_count_error")] + public long? DocCountError { get; init; } + [JsonInclude] [JsonPropertyName("key")] public double Key { get; init; } @@ -34,4 +47,63 @@ public partial class DoubleTermsBucket : TermsBucketBase [JsonPropertyName("key_as_string")] public string? KeyAsString { get; init; } } + + internal sealed class DoubleTermsBucketConverter : JsonConverter + { + public override DoubleTermsBucket? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}."); + var subAggs = new Dictionary(); // TODO - Optimise this and only create if we need it. + long docCount = default; + long? docCountError = default; + double key = default; + string? keyAsString = default; + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + break; + if (reader.TokenType != JsonTokenType.PropertyName) + throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}."); + var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those + reader.Read(); + if (name.Equals("doc_count", StringComparison.Ordinal)) + { + docCount = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("doc_count_error", StringComparison.Ordinal)) + { + docCountError = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("key", StringComparison.Ordinal)) + { + key = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("key_as_string", StringComparison.Ordinal)) + { + keyAsString = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Contains("#")) + { + AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name); + continue; + } + + throw new JsonException("Unknown property read from JSON."); + } + + return new DoubleTermsBucket(subAggs) + { DocCount = docCount, DocCountError = docCountError, Key = key, KeyAsString = keyAsString }; + } + + public override void Write(Utf8JsonWriter writer, DoubleTermsBucket value, JsonSerializerOptions options) => throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/FiltersBucket.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/FiltersBucket.g.cs index c55e36008e9..37c0cf4d764 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/FiltersBucket.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/FiltersBucket.g.cs @@ -24,7 +24,53 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Aggregations { - public partial class FiltersBucket : MultiBucketBase + [JsonConverter(typeof(FiltersBucketConverter))] + public sealed partial class FiltersBucket : AggregateDictionary { + public FiltersBucket(IReadOnlyDictionary backingDictionary) : base(backingDictionary) + { + } + + [JsonInclude] + [JsonPropertyName("doc_count")] + public long DocCount { get; init; } + } + + internal sealed class FiltersBucketConverter : JsonConverter + { + public override FiltersBucket? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}."); + var subAggs = new Dictionary(); // TODO - Optimise this and only create if we need it. + long docCount = default; + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + break; + if (reader.TokenType != JsonTokenType.PropertyName) + throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}."); + var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those + reader.Read(); + if (name.Equals("doc_count", StringComparison.Ordinal)) + { + docCount = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Contains("#")) + { + AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name); + continue; + } + + throw new JsonException("Unknown property read from JSON."); + } + + return new FiltersBucket(subAggs) + { DocCount = docCount }; + } + + public override void Write(Utf8JsonWriter writer, FiltersBucket value, JsonSerializerOptions options) => throw new NotImplementedException(); } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/HistogramBucket.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/HistogramBucket.g.cs index 5f3742206a8..c699d20fccd 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/HistogramBucket.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/HistogramBucket.g.cs @@ -24,8 +24,17 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Aggregations { - public partial class HistogramBucket : MultiBucketBase + [JsonConverter(typeof(HistogramBucketConverter))] + public sealed partial class HistogramBucket : AggregateDictionary { + public HistogramBucket(IReadOnlyDictionary backingDictionary) : base(backingDictionary) + { + } + + [JsonInclude] + [JsonPropertyName("doc_count")] + public long DocCount { get; init; } + [JsonInclude] [JsonPropertyName("key")] public double Key { get; init; } @@ -34,4 +43,56 @@ public partial class HistogramBucket : MultiBucketBase [JsonPropertyName("key_as_string")] public string? KeyAsString { get; init; } } + + internal sealed class HistogramBucketConverter : JsonConverter + { + public override HistogramBucket? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}."); + var subAggs = new Dictionary(); // TODO - Optimise this and only create if we need it. + long docCount = default; + double key = default; + string? keyAsString = default; + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + break; + if (reader.TokenType != JsonTokenType.PropertyName) + throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}."); + var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those + reader.Read(); + if (name.Equals("doc_count", StringComparison.Ordinal)) + { + docCount = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("key", StringComparison.Ordinal)) + { + key = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("key_as_string", StringComparison.Ordinal)) + { + keyAsString = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Contains("#")) + { + AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name); + continue; + } + + throw new JsonException("Unknown property read from JSON."); + } + + return new HistogramBucket(subAggs) + { DocCount = docCount, Key = key, KeyAsString = keyAsString }; + } + + public override void Write(Utf8JsonWriter writer, HistogramBucket value, JsonSerializerOptions options) => throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/IpRangeBucket.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/IpRangeBucket.g.cs index b61d5e89f0a..6835bfe28aa 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/IpRangeBucket.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/IpRangeBucket.g.cs @@ -24,8 +24,17 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Aggregations { - public partial class IpRangeBucket : MultiBucketBase + [JsonConverter(typeof(IpRangeBucketConverter))] + public sealed partial class IpRangeBucket : AggregateDictionary { + public IpRangeBucket(IReadOnlyDictionary backingDictionary) : base(backingDictionary) + { + } + + [JsonInclude] + [JsonPropertyName("doc_count")] + public long DocCount { get; init; } + [JsonInclude] [JsonPropertyName("from")] public string? From { get; init; } @@ -34,4 +43,56 @@ public partial class IpRangeBucket : MultiBucketBase [JsonPropertyName("to")] public string? To { get; init; } } + + internal sealed class IpRangeBucketConverter : JsonConverter + { + public override IpRangeBucket? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}."); + var subAggs = new Dictionary(); // TODO - Optimise this and only create if we need it. + long docCount = default; + string? from = default; + string? to = default; + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + break; + if (reader.TokenType != JsonTokenType.PropertyName) + throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}."); + var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those + reader.Read(); + if (name.Equals("doc_count", StringComparison.Ordinal)) + { + docCount = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("from", StringComparison.Ordinal)) + { + from = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("to", StringComparison.Ordinal)) + { + to = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Contains("#")) + { + AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name); + continue; + } + + throw new JsonException("Unknown property read from JSON."); + } + + return new IpRangeBucket(subAggs) + { DocCount = docCount, From = from, To = to }; + } + + public override void Write(Utf8JsonWriter writer, IpRangeBucket value, JsonSerializerOptions options) => throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/LongTermsBucket.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/LongTermsBucket.g.cs index ee12b008b4b..c909b9e927e 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/LongTermsBucket.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/LongTermsBucket.g.cs @@ -24,8 +24,21 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Aggregations { - public partial class LongTermsBucket : TermsBucketBase + [JsonConverter(typeof(LongTermsBucketConverter))] + public sealed partial class LongTermsBucket : AggregateDictionary { + public LongTermsBucket(IReadOnlyDictionary backingDictionary) : base(backingDictionary) + { + } + + [JsonInclude] + [JsonPropertyName("doc_count")] + public long DocCount { get; init; } + + [JsonInclude] + [JsonPropertyName("doc_count_error")] + public long? DocCountError { get; init; } + [JsonInclude] [JsonPropertyName("key")] public long Key { get; init; } @@ -34,4 +47,63 @@ public partial class LongTermsBucket : TermsBucketBase [JsonPropertyName("key_as_string")] public string? KeyAsString { get; init; } } + + internal sealed class LongTermsBucketConverter : JsonConverter + { + public override LongTermsBucket? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}."); + var subAggs = new Dictionary(); // TODO - Optimise this and only create if we need it. + long docCount = default; + long? docCountError = default; + long key = default; + string? keyAsString = default; + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + break; + if (reader.TokenType != JsonTokenType.PropertyName) + throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}."); + var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those + reader.Read(); + if (name.Equals("doc_count", StringComparison.Ordinal)) + { + docCount = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("doc_count_error", StringComparison.Ordinal)) + { + docCountError = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("key", StringComparison.Ordinal)) + { + key = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("key_as_string", StringComparison.Ordinal)) + { + keyAsString = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Contains("#")) + { + AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name); + continue; + } + + throw new JsonException("Unknown property read from JSON."); + } + + return new LongTermsBucket(subAggs) + { DocCount = docCount, DocCountError = docCountError, Key = key, KeyAsString = keyAsString }; + } + + public override void Write(Utf8JsonWriter writer, LongTermsBucket value, JsonSerializerOptions options) => throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/MultiTermsBucket.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/MultiTermsBucket.g.cs index 255543f12e0..537d489f9c3 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/MultiTermsBucket.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/MultiTermsBucket.g.cs @@ -24,8 +24,17 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Aggregations { - public partial class MultiTermsBucket : MultiBucketBase + [JsonConverter(typeof(MultiTermsBucketConverter))] + public sealed partial class MultiTermsBucket : AggregateDictionary { + public MultiTermsBucket(IReadOnlyDictionary backingDictionary) : base(backingDictionary) + { + } + + [JsonInclude] + [JsonPropertyName("doc_count")] + public long DocCount { get; init; } + [JsonInclude] [JsonPropertyName("doc_count_error_upper_bound")] public long? DocCountErrorUpperBound { get; init; } @@ -38,4 +47,63 @@ public partial class MultiTermsBucket : MultiBucketBase [JsonPropertyName("key_as_string")] public string? KeyAsString { get; init; } } + + internal sealed class MultiTermsBucketConverter : JsonConverter + { + public override MultiTermsBucket? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}."); + var subAggs = new Dictionary(); // TODO - Optimise this and only create if we need it. + long docCount = default; + long? docCountErrorUpperBound = default; + IReadOnlyCollection key = default; + string? keyAsString = default; + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + break; + if (reader.TokenType != JsonTokenType.PropertyName) + throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}."); + var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those + reader.Read(); + if (name.Equals("doc_count", StringComparison.Ordinal)) + { + docCount = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("doc_count_error_upper_bound", StringComparison.Ordinal)) + { + docCountErrorUpperBound = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("key", StringComparison.Ordinal)) + { + key = JsonSerializer.Deserialize>(ref reader, options); + continue; + } + + if (name.Equals("key_as_string", StringComparison.Ordinal)) + { + keyAsString = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Contains("#")) + { + AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name); + continue; + } + + throw new JsonException("Unknown property read from JSON."); + } + + return new MultiTermsBucket(subAggs) + { DocCount = docCount, DocCountErrorUpperBound = docCountErrorUpperBound, Key = key, KeyAsString = keyAsString }; + } + + public override void Write(Utf8JsonWriter writer, MultiTermsBucket value, JsonSerializerOptions options) => throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/RangeBucket.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/RangeBucket.g.cs index 8a65302552d..8e09e73b5f4 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/RangeBucket.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/RangeBucket.g.cs @@ -24,8 +24,17 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Aggregations { - public partial class RangeBucket : MultiBucketBase + [JsonConverter(typeof(RangeBucketConverter))] + public sealed partial class RangeBucket : AggregateDictionary { + public RangeBucket(IReadOnlyDictionary backingDictionary) : base(backingDictionary) + { + } + + [JsonInclude] + [JsonPropertyName("doc_count")] + public long DocCount { get; init; } + [JsonInclude] [JsonPropertyName("from")] public double? From { get; init; } @@ -46,4 +55,77 @@ public partial class RangeBucket : MultiBucketBase [JsonPropertyName("to_as_string")] public string? ToAsString { get; init; } } + + internal sealed class RangeBucketConverter : JsonConverter + { + public override RangeBucket? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}."); + var subAggs = new Dictionary(); // TODO - Optimise this and only create if we need it. + long docCount = default; + double? from = default; + string? fromAsString = default; + string? key = default; + double? to = default; + string? toAsString = default; + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + break; + if (reader.TokenType != JsonTokenType.PropertyName) + throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}."); + var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those + reader.Read(); + if (name.Equals("doc_count", StringComparison.Ordinal)) + { + docCount = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("from", StringComparison.Ordinal)) + { + from = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("from_as_string", StringComparison.Ordinal)) + { + fromAsString = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("key", StringComparison.Ordinal)) + { + key = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("to", StringComparison.Ordinal)) + { + to = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("to_as_string", StringComparison.Ordinal)) + { + toAsString = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Contains("#")) + { + AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name); + continue; + } + + throw new JsonException("Unknown property read from JSON."); + } + + return new RangeBucket(subAggs) + { DocCount = docCount, From = from, FromAsString = fromAsString, Key = key, To = to, ToAsString = toAsString }; + } + + public override void Write(Utf8JsonWriter writer, RangeBucket value, JsonSerializerOptions options) => throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/StringTermsBucket.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/StringTermsBucket.g.cs index 6cf931763b0..aabf51ffcb9 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/StringTermsBucket.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/StringTermsBucket.g.cs @@ -24,10 +24,75 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Aggregations { - public partial class StringTermsBucket : TermsBucketBase + [JsonConverter(typeof(StringTermsBucketConverter))] + public sealed partial class StringTermsBucket : AggregateDictionary { + public StringTermsBucket(IReadOnlyDictionary backingDictionary) : base(backingDictionary) + { + } + + [JsonInclude] + [JsonPropertyName("doc_count")] + public long DocCount { get; init; } + + [JsonInclude] + [JsonPropertyName("doc_count_error")] + public long? DocCountError { get; init; } + [JsonInclude] [JsonPropertyName("key")] public string Key { get; init; } } + + internal sealed class StringTermsBucketConverter : JsonConverter + { + public override StringTermsBucket? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}."); + var subAggs = new Dictionary(); // TODO - Optimise this and only create if we need it. + long docCount = default; + long? docCountError = default; + string key = default; + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + break; + if (reader.TokenType != JsonTokenType.PropertyName) + throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}."); + var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those + reader.Read(); + if (name.Equals("doc_count", StringComparison.Ordinal)) + { + docCount = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("doc_count_error", StringComparison.Ordinal)) + { + docCountError = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("key", StringComparison.Ordinal)) + { + key = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Contains("#")) + { + AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name); + continue; + } + + throw new JsonException("Unknown property read from JSON."); + } + + return new StringTermsBucket(subAggs) + { DocCount = docCount, DocCountError = docCountError, Key = key }; + } + + public override void Write(Utf8JsonWriter writer, StringTermsBucket value, JsonSerializerOptions options) => throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/VariableWidthHistogramBucket.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/VariableWidthHistogramBucket.g.cs index 84d6d0f964c..5e993625c61 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/VariableWidthHistogramBucket.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/VariableWidthHistogramBucket.g.cs @@ -24,8 +24,17 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Aggregations { - public partial class VariableWidthHistogramBucket : MultiBucketBase + [JsonConverter(typeof(VariableWidthHistogramBucketConverter))] + public sealed partial class VariableWidthHistogramBucket : AggregateDictionary { + public VariableWidthHistogramBucket(IReadOnlyDictionary backingDictionary) : base(backingDictionary) + { + } + + [JsonInclude] + [JsonPropertyName("doc_count")] + public long DocCount { get; init; } + [JsonInclude] [JsonPropertyName("key")] public double Key { get; init; } @@ -50,4 +59,84 @@ public partial class VariableWidthHistogramBucket : MultiBucketBase [JsonPropertyName("min_as_string")] public string? MinAsString { get; init; } } + + internal sealed class VariableWidthHistogramBucketConverter : JsonConverter + { + public override VariableWidthHistogramBucket? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}."); + var subAggs = new Dictionary(); // TODO - Optimise this and only create if we need it. + long docCount = default; + double key = default; + string? keyAsString = default; + double max = default; + string? maxAsString = default; + double min = default; + string? minAsString = default; + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + break; + if (reader.TokenType != JsonTokenType.PropertyName) + throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}."); + var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those + reader.Read(); + if (name.Equals("doc_count", StringComparison.Ordinal)) + { + docCount = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("key", StringComparison.Ordinal)) + { + key = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("key_as_string", StringComparison.Ordinal)) + { + keyAsString = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("max", StringComparison.Ordinal)) + { + max = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("max_as_string", StringComparison.Ordinal)) + { + maxAsString = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("min", StringComparison.Ordinal)) + { + min = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Equals("min_as_string", StringComparison.Ordinal)) + { + minAsString = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (name.Contains("#")) + { + AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name); + continue; + } + + throw new JsonException("Unknown property read from JSON."); + } + + return new VariableWidthHistogramBucket(subAggs) + { DocCount = docCount, Key = key, KeyAsString = keyAsString, Max = max, MaxAsString = maxAsString, Min = min, MinAsString = minAsString }; + } + + public override void Write(Utf8JsonWriter writer, VariableWidthHistogramBucket value, JsonSerializerOptions options) => throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/Playground/Program.cs b/src/Playground/Program.cs index 2bc6f874dc6..b54b420df08 100644 --- a/src/Playground/Program.cs +++ b/src/Playground/Program.cs @@ -2,68 +2,223 @@ // 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.Text; using Elastic.Clients.Elasticsearch; -using Elastic.Clients.Elasticsearch.IndexManagement; +using Elastic.Clients.Elasticsearch.Aggregations; +using Elastic.Clients.Elasticsearch.Helpers; using Elastic.Clients.Elasticsearch.Mapping; +using Elastic.Clients.Elasticsearch.QueryDsl; +using Elastic.Transport; -var client = new ElasticsearchClient(); +const string IndexName = "stock-demo-v1"; -var putTemplateRequest = new PutIndexTemplateRequest("my-template") +var settings = new ElasticsearchClientSettings(new Uri("https://localhost:9200")) + .CertificateFingerprint("E8:76:3D:91:81:8C:57:31:6F:2F:E0:4C:17:78:78:FB:38:CC:37:27:41:7A:94:B4:12:AA:B6:D1:D6:C4:4C:7D") + .Authentication(new BasicAuthentication("elastic", "password")) + .EnableDebugMode(); + +var client = new ElasticsearchClient(settings); + +var existsResponse = await client.Indices.ExistsAsync(IndexName); + +if (!existsResponse.Exists) { - Template = new IndexTemplateMapping - { - Mappings = new TypeMapping - { - Properties = new Properties + var newIndexResponse = await client.Indices.CreateAsync(IndexName, i => i + .Mappings(m => m + .Properties(new Elastic.Clients.Elasticsearch.Mapping.Properties { - { "field1", new TextProperty { Boost = 2.0, Store = false } } - } - }, - Settings = new IndexSettings + { "symbol", new KeywordProperty() }, + { "high", new FloatNumberProperty() }, + { "low", new FloatNumberProperty() }, + { "open", new FloatNumberProperty() }, + { "close", new FloatNumberProperty() }, + })) + //.Map(m => m + // .AutoMap() + // .Properties(p => p.Keyword(k => k.Name(n => n.Symbol)))) + .Settings(s => s.NumberOfShards(1).NumberOfReplicas(0))); + + if (!newIndexResponse.IsValid || newIndexResponse.Acknowledged is false) + throw new Exception("Oh no!"); + + var bulkAll = client.BulkAll(ReadStockData(), r => r + .Index(IndexName) + .BackOffRetries(20) + .BackOffTime(TimeSpan.FromSeconds(10)) + .ContinueAfterDroppedDocuments() + .DroppedDocumentCallback((r, d) => { - Index = new IndexSettings - { - NumberOfReplicas = 1, - Priority = 2, - } - } + Console.WriteLine(r.Error?.Reason ?? "NO REASON"); + }) + .MaxDegreeOfParallelism(4) + .Size(1000)); + + bulkAll.Wait(TimeSpan.FromMinutes(10), r => Console.WriteLine("Data indexed")); +} + +var aggExampleResponse = await client.SearchAsync(s => s + .Index(IndexName) + .Size(0) + .Query(q => q + .Bool(b => b + .Filter(new[] { new QueryContainer(new TermQuery { Field = "symbol", Value = "MSFT" }) }))) + .Aggregations(a => a + .DateHistogram("by-month", dh => dh + .CalendarInterval(CalendarInterval.Month) + .Field(fld => fld.Date) + //.Order(HistogramOrder.KeyDescending) + .Order(new HistogramOrder { Key = SortOrder.Desc }) + .Aggregations(agg => agg + .Sum("trade-volumes", sum => sum.Field(fld => fld.Volume)))))); + +if (!aggExampleResponse.IsValid) throw new Exception("Oh no"); + +var monthlyBuckets = aggExampleResponse.Aggregations?.GetDateHistogram("by-month")?.Buckets ?? Array.Empty(); + +foreach (var monthlyBucket in monthlyBuckets) +{ + //var volume = monthlyBucket..Sum("trade-volumes").Value; + //Console.WriteLine($"{monthlyBucket.Date} : {volume:n0}"); +} + +Console.WriteLine("Press any key to exit."); +Console.ReadKey(); + +static IEnumerable ReadStockData() +{ + var file = new StreamReader("c:\\stock-data\\all_stocks_5yr.csv"); + + string? line; + while ((line = file.ReadLine()) is not null) + { + yield return new StockData(line); } -}; +} + +public class StockData +{ + private static readonly Dictionary CompanyLookup = new() + { + { "AAL", "American Airlines Group Inc" }, + { "MSFT", "Microsoft Corporation" }, + { "AME", "AMETEK, Inc." }, + { "M", "Macy's inc" } + }; + + public StockData(string dataLine) + { + var columns = dataLine.Split(',', StringSplitOptions.TrimEntries); + + if (DateTime.TryParse(columns[0], out var date)) + Date = date; + + if (double.TryParse(columns[1], out var open)) + Open = open; + + if (double.TryParse(columns[2], out var high)) + High = high; -//var putMappingRequest = new PutMappingRequest("test-index") + if (double.TryParse(columns[3], out var low)) + Low = low; + + if (double.TryParse(columns[4], out var close)) + Close = close; + + if (uint.TryParse(columns[5], out var volume)) + Volume = volume; + + Symbol = columns[6]; + + if (CompanyLookup.TryGetValue(Symbol, out var name)) + Name = name; + } + + public DateTime Date { get; init; } + public double Open { get; init; } + public double Close { get; init; } + public double High { get; init; } + public double Low { get; init; } + public uint Volume { get; init; } + public string Symbol { get; init; } + public string? Name { get; init; } +} + +//using System.Text; +//using Elastic.Clients.Elasticsearch; +//using Elastic.Clients.Elasticsearch.IndexManagement; +//using Elastic.Clients.Elasticsearch.Mapping; +//using Elastic.Transport; +//using Playground; + + + + +//var settings = new ElasticsearchClientSettings(new InMemoryConnection()) +// .EnableDebugMode() +// .DefaultMappingFor(p => p +// .PropertyName(pn => pn.Age, "custom-name") +// .Ignore(pn => pn.Email)); + +//var client = new ElasticsearchClient(settings); + +//var response = await client.IndexAsync(new Person { FirstName = "Steve", LastName = "Gordon", Age = 37, Email = "test@example.com", Id = 1000 }, "test-index"); + + + +//var putTemplateRequest = new PutIndexTemplateRequest("my-template") //{ -// Properties = new Properties +// Template = new IndexTemplateMapping // { -// { "field1", new TextProperty { Boost = 2.0, Store = false } } +// Mappings = new TypeMapping +// { +// Properties = new Properties +// { +// { "field1", new KeywordProperty { Boost = 2.0, Store = false } } +// } +// }, +// Settings = new IndexSettings +// { +// Index = new IndexSettings +// { +// NumberOfReplicas = 1, +// Priority = 2, +// } +// } // } //}; -var stream = new MemoryStream(); +////var putMappingRequest = new PutMappingRequest("test-index") +////{ +//// Properties = new Properties +//// { +//// { "field1", new TextProperty { Boost = 2.0, Store = false } } +//// } +////}; -client.RequestResponseSerializer.Serialize(putTemplateRequest, stream); +//var stream = new MemoryStream(); -stream.Position = 0; +//client.RequestResponseSerializer.Serialize(putTemplateRequest, stream); -var sr = new StreamReader(stream); +//stream.Position = 0; -var json = sr.ReadToEnd(); +//var sr = new StreamReader(stream); -Console.WriteLine(json); +//var json = sr.ReadToEnd(); -Console.ReadKey(); +//Console.WriteLine(json); -//const string propertiesJson = @"{""field1"":{""boost"":2,""type"":""text"",""store"":false},""field2"":{""type"":""ip""},""name"":{""properties"":{""first"":{""type"":""text"",""fields"":{""keyword"":{""type"":""keyword"",""ignore_above"":256}}},""last"":{""type"":""text"",""fields"":{""keyword"":{""type"":""keyword"",""ignore_above"":256}}}}}}"; +//Console.ReadKey(); -//stream = new MemoryStream(Encoding.UTF8.GetBytes(propertiesJson)); +////const string propertiesJson = @"{""field1"":{""boost"":2,""type"":""text"",""store"":false},""field2"":{""type"":""ip""},""name"":{""properties"":{""first"":{""type"":""text"",""fields"":{""keyword"":{""type"":""keyword"",""ignore_above"":256}}},""last"":{""type"":""text"",""fields"":{""keyword"":{""type"":""keyword"",""ignore_above"":256}}}}}}"; -//var properties = client.RequestResponseSerializer.Deserialize(stream); +////stream = new MemoryStream(Encoding.UTF8.GetBytes(propertiesJson)); -//if (properties.TryGetProperty("field1", out var textProperty)) -//{ -// Console.WriteLine($"Found field1 with boost: {textProperty.Boost}"); -//} +////var properties = client.RequestResponseSerializer.Deserialize(stream); -Console.WriteLine("DONE"); +////if (properties.TryGetProperty("field1", out var textProperty)) +////{ +//// Console.WriteLine($"Found field1 with boost: {textProperty.Boost}"); +////} -Console.ReadKey(); +//Console.WriteLine("DONE"); + +//Console.ReadKey(); diff --git a/tests/Tests/Aggregations/AggregationMetaUsageTests.cs b/tests/Tests/Aggregations/AggregationMetaUsageTests.cs index 925a29796b8..89cacea06c1 100644 --- a/tests/Tests/Aggregations/AggregationMetaUsageTests.cs +++ b/tests/Tests/Aggregations/AggregationMetaUsageTests.cs @@ -61,7 +61,7 @@ public AggregationMetaUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base( protected override void ExpectResponse(SearchResponse response) { response.ShouldBeValid(); - var min = response.Aggregations.Min("min_last_activity"); + var min = response.Aggregations.GetMin("min_last_activity"); min.Meta.Should().NotBeNull().And.ContainKeys("meta_1", "meta_2", "meta_3"); } } diff --git a/tests/Tests/Aggregations/Bucket/DateHistogramAggregationUsageTests.cs b/tests/Tests/Aggregations/Bucket/DateHistogramAggregationUsageTests.cs index 0ae432c1980..c00ed1cdf09 100644 --- a/tests/Tests/Aggregations/Bucket/DateHistogramAggregationUsageTests.cs +++ b/tests/Tests/Aggregations/Bucket/DateHistogramAggregationUsageTests.cs @@ -102,7 +102,7 @@ protected override void ExpectResponse(SearchResponse response) { response.ShouldBeValid(); - var dateHistogram = response.Aggregations.DateHistogram("projects_started_per_month"); + var dateHistogram = response.Aggregations.GetDateHistogram("projects_started_per_month"); dateHistogram.Should().NotBeNull(); //dateHistogram.Buckets.Should().NotBeNull(); //dateHistogram.Buckets.Count.Should().BeGreaterThan(10); diff --git a/tests/Tests/Aggregations/Metric/BoxplotAggregationUsageTests.cs b/tests/Tests/Aggregations/Metric/BoxplotAggregationUsageTests.cs index 4b8369c8e28..382c5b2abe6 100644 --- a/tests/Tests/Aggregations/Metric/BoxplotAggregationUsageTests.cs +++ b/tests/Tests/Aggregations/Metric/BoxplotAggregationUsageTests.cs @@ -58,7 +58,7 @@ public BoxplotAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) : ba protected override void ExpectResponse(SearchResponse response) { response.ShouldBeValid(); - var boxplot = response.Aggregations.BoxPlot("boxplot_commits"); + var boxplot = response.Aggregations.GetBoxPlot("boxplot_commits"); boxplot.Should().NotBeNull(); boxplot.Min.Should().BeGreaterOrEqualTo(0); boxplot.Max.Should().BeGreaterOrEqualTo(0); diff --git a/tests/Tests/Aggregations/Metric/CardinalityAggregationUsageTests.cs b/tests/Tests/Aggregations/Metric/CardinalityAggregationUsageTests.cs index 5a6356e3363..a637c6a7c62 100644 --- a/tests/Tests/Aggregations/Metric/CardinalityAggregationUsageTests.cs +++ b/tests/Tests/Aggregations/Metric/CardinalityAggregationUsageTests.cs @@ -43,7 +43,7 @@ public CardinalityAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) protected override void ExpectResponse(SearchResponse response) { response.ShouldBeValid(); - var projectCount = response.Aggregations.Cardinality("state_count"); + var projectCount = response.Aggregations.GetCardinality("state_count"); projectCount.Should().NotBeNull(); projectCount.Value.Should().BeGreaterOrEqualTo(1); } diff --git a/tests/Tests/Aggregations/Metric/ExtendedStatsAggregationUsageTests.cs b/tests/Tests/Aggregations/Metric/ExtendedStatsAggregationUsageTests.cs index 6fc01151a4d..cc168694ca9 100644 --- a/tests/Tests/Aggregations/Metric/ExtendedStatsAggregationUsageTests.cs +++ b/tests/Tests/Aggregations/Metric/ExtendedStatsAggregationUsageTests.cs @@ -44,7 +44,7 @@ public ExtendedStatsAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage protected override void ExpectResponse(SearchResponse response) { response.ShouldBeValid(); - var commitStats = response.Aggregations.ExtendedStats("commit_stats"); + var commitStats = response.Aggregations.GetExtendedStats("commit_stats"); commitStats.Should().NotBeNull(); commitStats.Avg.Should().BeGreaterThan(0); commitStats.Max.Should().BeGreaterThan(0); diff --git a/tests/Tests/Aggregations/Metric/MaxAggregationUsageTests.cs b/tests/Tests/Aggregations/Metric/MaxAggregationUsageTests.cs index 27c2ab6fc0b..3ab6f39757f 100644 --- a/tests/Tests/Aggregations/Metric/MaxAggregationUsageTests.cs +++ b/tests/Tests/Aggregations/Metric/MaxAggregationUsageTests.cs @@ -39,7 +39,7 @@ public MaxAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i protected override void ExpectResponse(SearchResponse response) { response.ShouldBeValid(); - var max = response.Aggregations.Max("max_commits"); + var max = response.Aggregations.GetMax("max_commits"); max.Should().NotBeNull(); max.Value.Should().BeGreaterThan(0); } diff --git a/tests/Tests/Aggregations/Metric/MedianAbsoluteDeviationAggregationUsageTests.cs b/tests/Tests/Aggregations/Metric/MedianAbsoluteDeviationAggregationUsageTests.cs index 6ede8e5bea5..ecc6882e5d6 100644 --- a/tests/Tests/Aggregations/Metric/MedianAbsoluteDeviationAggregationUsageTests.cs +++ b/tests/Tests/Aggregations/Metric/MedianAbsoluteDeviationAggregationUsageTests.cs @@ -48,7 +48,7 @@ public MedianAbsoluteDeviationAggregationUsageTests(ReadOnlyCluster i, EndpointU protected override void ExpectResponse(SearchResponse response) { response.ShouldBeValid(); - var medianAbsoluteDeviation = response.Aggregations.MedianAbsoluteDeviation("commit_variability"); + var medianAbsoluteDeviation = response.Aggregations.GetMedianAbsoluteDeviation("commit_variability"); medianAbsoluteDeviation.Should().NotBeNull(); medianAbsoluteDeviation.Value.Should().BeGreaterThan(0); } diff --git a/tests/Tests/Aggregations/Metric/MinAggregationUsageTests.cs b/tests/Tests/Aggregations/Metric/MinAggregationUsageTests.cs index f0c0617a011..8631b0d1160 100644 --- a/tests/Tests/Aggregations/Metric/MinAggregationUsageTests.cs +++ b/tests/Tests/Aggregations/Metric/MinAggregationUsageTests.cs @@ -40,7 +40,7 @@ public MinAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i protected override void ExpectResponse(SearchResponse response) { response.ShouldBeValid(); - var min = response.Aggregations.Min("min_last_activity"); + var min = response.Aggregations.GetMin("min_last_activity"); min.Should().NotBeNull(); min.Value.Should().BeGreaterThan(0); min.ValueAsString.Should().NotBeNullOrEmpty(); diff --git a/tests/Tests/Aggregations/Metric/StatsAggregationUsageTests.cs b/tests/Tests/Aggregations/Metric/StatsAggregationUsageTests.cs index e42fcce56d8..3b34f187086 100644 --- a/tests/Tests/Aggregations/Metric/StatsAggregationUsageTests.cs +++ b/tests/Tests/Aggregations/Metric/StatsAggregationUsageTests.cs @@ -38,7 +38,7 @@ public StatsAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base protected override void ExpectResponse(SearchResponse response) { response.ShouldBeValid(); - var commitStats = response.Aggregations.Stats("commit_stats"); + var commitStats = response.Aggregations.GetStats("commit_stats"); commitStats.Should().NotBeNull(); commitStats.Avg.Should().BeGreaterThan(0); commitStats.Max.Should().BeGreaterThan(0); diff --git a/tests/Tests/Aggregations/Metric/StringStatsAggregationUsageTests.cs b/tests/Tests/Aggregations/Metric/StringStatsAggregationUsageTests.cs index 73a02fd5910..6474a02d1fb 100644 --- a/tests/Tests/Aggregations/Metric/StringStatsAggregationUsageTests.cs +++ b/tests/Tests/Aggregations/Metric/StringStatsAggregationUsageTests.cs @@ -38,7 +38,7 @@ public StringStatsAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) protected override void ExpectResponse(SearchResponse response) { response.ShouldBeValid(); - var commitStats = response.Aggregations.StringStats("name_stats"); + var commitStats = response.Aggregations.GetStringStats("name_stats"); commitStats.Should().NotBeNull(); commitStats.AvgLength.Should().BeGreaterThan(0); commitStats.MaxLength.Should().BeGreaterThan(0); diff --git a/tests/Tests/Aggregations/Metric/StringStatsWithDistributionAggregationUsageTests.cs b/tests/Tests/Aggregations/Metric/StringStatsWithDistributionAggregationUsageTests.cs index 07cfeb2b200..e01d34b2228 100644 --- a/tests/Tests/Aggregations/Metric/StringStatsWithDistributionAggregationUsageTests.cs +++ b/tests/Tests/Aggregations/Metric/StringStatsWithDistributionAggregationUsageTests.cs @@ -43,7 +43,7 @@ public StringStatsWithDistributionAggregationUsageTests(ReadOnlyCluster i, Endpo protected override void ExpectResponse(SearchResponse response) { response.ShouldBeValid(); - var commitStats = response.Aggregations.StringStats("name_stats"); + var commitStats = response.Aggregations.GetStringStats("name_stats"); commitStats.Should().NotBeNull(); commitStats.AvgLength.Should().BeGreaterThan(0); commitStats.MaxLength.Should().BeGreaterThan(0); diff --git a/tests/Tests/Aggregations/Metric/SumAggregationUsageTests.cs b/tests/Tests/Aggregations/Metric/SumAggregationUsageTests.cs index 29dd3cf4785..983e89402e9 100644 --- a/tests/Tests/Aggregations/Metric/SumAggregationUsageTests.cs +++ b/tests/Tests/Aggregations/Metric/SumAggregationUsageTests.cs @@ -39,7 +39,7 @@ public SumAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i protected override void ExpectResponse(SearchResponse response) { response.ShouldBeValid(); - var commitsSum = response.Aggregations.Sum("commits_sum"); + var commitsSum = response.Aggregations.GetSum("commits_sum"); commitsSum.Should().NotBeNull(); commitsSum.Value.Should().BeGreaterThan(0); } diff --git a/tests/Tests/Aggregations/Metric/ValueCountAggregationUsageTests.cs b/tests/Tests/Aggregations/Metric/ValueCountAggregationUsageTests.cs index c0ed982169a..cd889ca563a 100644 --- a/tests/Tests/Aggregations/Metric/ValueCountAggregationUsageTests.cs +++ b/tests/Tests/Aggregations/Metric/ValueCountAggregationUsageTests.cs @@ -39,7 +39,7 @@ public ValueCountAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) : protected override void ExpectResponse(SearchResponse response) { response.ShouldBeValid(); - var commitCount = response.Aggregations.ValueCount("commit_count"); + var commitCount = response.Aggregations.GetValueCount("commit_count"); commitCount.Should().NotBeNull(); commitCount.Value.Should().BeGreaterThan(0); } diff --git a/tests/Tests/Aggregations/Metric/WeightedAverageAggregationUsageTests.cs b/tests/Tests/Aggregations/Metric/WeightedAverageAggregationUsageTests.cs index 32bbc4bbe42..29f46a29f8a 100644 --- a/tests/Tests/Aggregations/Metric/WeightedAverageAggregationUsageTests.cs +++ b/tests/Tests/Aggregations/Metric/WeightedAverageAggregationUsageTests.cs @@ -66,7 +66,7 @@ public WeightedAverageAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usa protected override void ExpectResponse(SearchResponse response) { response.ShouldBeValid(); - var commitsAvg = response.Aggregations.WeightedAvg("weighted_avg_commits"); + var commitsAvg = response.Aggregations.GetWeightedAvg("weighted_avg_commits"); commitsAvg.Should().NotBeNull(); commitsAvg.Value.Should().BeGreaterThan(0); } diff --git a/tests/Tests/Serialization/Aggregations/BoxplotAggregateDeserializationTests.cs b/tests/Tests/Serialization/Aggregations/BoxplotAggregateDeserializationTests.cs index 9af62b941c0..a6ce04e0afe 100644 --- a/tests/Tests/Serialization/Aggregations/BoxplotAggregateDeserializationTests.cs +++ b/tests/Tests/Serialization/Aggregations/BoxplotAggregateDeserializationTests.cs @@ -18,7 +18,7 @@ public void CanDeserializeAggregate() search.Aggregations.Should().HaveCount(1); - var agg = search.Aggregations.BoxPlot("my-agg-name"); + var agg = search.Aggregations.GetBoxPlot("my-agg-name"); agg.Min.Should().Be(1); agg.Max.Should().Be(990); agg.Q1.Should().Be(165); diff --git a/tests/Tests/Serialization/Aggregations/BucketSubAggregationSerializationTests.cs b/tests/Tests/Serialization/Aggregations/BucketSubAggregationSerializationTests.cs new file mode 100644 index 00000000000..08b4c728ade --- /dev/null +++ b/tests/Tests/Serialization/Aggregations/BucketSubAggregationSerializationTests.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. + +using System.Linq; +namespace Tests.Serialization; + +public class BucketSubAggregationSerializationTests : SerializerTestBase +{ + [U] + public void DeserializeSubAggsForDateHistorgram() + { + const string json = @"{""took"":3,""timed_out"":false,""_shards"":{""total"":1,""successful"":1,""skipped"":0,""failed"":0}, +""hits"":{""total"":{""value"":1259,""relation"":""eq""},""max_score"":null,""hits"":[]},""aggregations"":{""date_histogram#by-month"":{""buckets"":[{ +""key_as_string"":""2018-02-01T00:00:00.000Z"",""key"":1517443200000,""doc_count"":5,""sum#trade-volumes"":{""value"":255233256},""sum#trade-volumes-two"":{""value"":255233256}}]}}}"; + + var searchResponse = DeserializeJsonString>(json); + + var dateHistogramAgg = searchResponse.Aggregations.GetDateHistogram("by-month"); + + dateHistogramAgg.Should().NotBeNull(); + dateHistogramAgg.Buckets.Should().HaveCount(1); + + var dateBucket = dateHistogramAgg.Buckets.First(); + + dateBucket.Key.Should().Be(new EpochMillis(1517443200000)); + dateBucket.KeyAsString.Should().Be("2018-02-01T00:00:00.000Z"); + + var firstSum = dateBucket.GetSum("trade-volumes"); + + firstSum.Should().NotBeNull(); + firstSum.Value.Should().Be(255233256); + + dateBucket.GetSum("trade-volumes-two").Should().NotBeNull(); + } +} diff --git a/tests/Tests/Serialization/Aggregations/CardinalityAggregateDeserializationTests.cs b/tests/Tests/Serialization/Aggregations/CardinalityAggregateDeserializationTests.cs index 81777556034..b757b134a8e 100644 --- a/tests/Tests/Serialization/Aggregations/CardinalityAggregateDeserializationTests.cs +++ b/tests/Tests/Serialization/Aggregations/CardinalityAggregateDeserializationTests.cs @@ -18,7 +18,7 @@ public void CanDeserializeAggregate() search.Aggregations.Should().HaveCount(1); - var agg = search.Aggregations.Cardinality("my-agg-name"); + var agg = search.Aggregations.GetCardinality("my-agg-name"); agg.Value.Should().Be(75); } } diff --git a/tests/Tests/Serialization/Aggregations/ExtendedStatsAggregateDeserializationTests.cs b/tests/Tests/Serialization/Aggregations/ExtendedStatsAggregateDeserializationTests.cs index 988fcf992e9..4b9c3be2139 100644 --- a/tests/Tests/Serialization/Aggregations/ExtendedStatsAggregateDeserializationTests.cs +++ b/tests/Tests/Serialization/Aggregations/ExtendedStatsAggregateDeserializationTests.cs @@ -20,7 +20,7 @@ public void CanDeserializeAggregate() search.Aggregations.Should().HaveCount(1); - var agg = search.Aggregations.ExtendedStats("my-agg-name"); + var agg = search.Aggregations.GetExtendedStats("my-agg-name"); agg.Count.Should().Be(2); agg.Min.Should().Be(50); agg.Max.Should().Be(100); diff --git a/tests/Tests/Serialization/Aggregations/SumAggregateDeserializationTests.cs b/tests/Tests/Serialization/Aggregations/SumAggregateDeserializationTests.cs index 37fa2fa4ac4..15c148b071a 100644 --- a/tests/Tests/Serialization/Aggregations/SumAggregateDeserializationTests.cs +++ b/tests/Tests/Serialization/Aggregations/SumAggregateDeserializationTests.cs @@ -17,7 +17,7 @@ public void CanDeserializeAggregate() search.Aggregations.Should().HaveCount(1); - var agg = search.Aggregations.Sum("my-agg-name"); + var agg = search.Aggregations.GetSum("my-agg-name"); agg.Value.HasValue.Should().BeTrue(); agg.Value.Should().Be(75); } @@ -33,7 +33,7 @@ public void CanDeserializeAggregate_WithNullValue() search.Aggregations.Should().HaveCount(1); - var agg = search.Aggregations.Sum("my-agg-name"); + var agg = search.Aggregations.GetSum("my-agg-name"); agg.Value.HasValue.Should().BeFalse(); } } diff --git a/tests/Tests/Serialization/Aggregations/TermsAggregateDeserializationTests.cs b/tests/Tests/Serialization/Aggregations/TermsAggregateDeserializationTests.cs index 7ec68411b4a..1cb4ffcac0f 100644 --- a/tests/Tests/Serialization/Aggregations/TermsAggregateDeserializationTests.cs +++ b/tests/Tests/Serialization/Aggregations/TermsAggregateDeserializationTests.cs @@ -21,7 +21,7 @@ public void CanDeserialize_BasicStringTermsAggregate() search.Aggregations.Should().HaveCount(1); - var termsAgg = search.Aggregations.StringTerms("my-agg-name"); + var termsAgg = search.Aggregations.GetStringTerms("my-agg-name"); termsAgg.DocCountErrorUpperBound.Should().Be(10); termsAgg.SumOtherDocCount.Should().Be(200); termsAgg.Buckets.Should().HaveCount(2); @@ -49,7 +49,7 @@ public void CanDeserialize_BasicLongTermsAggregate() search.Aggregations.Should().HaveCount(1); - var termsAgg = search.Aggregations.LongTerms("my-agg-name"); + var termsAgg = search.Aggregations.GetLongTerms("my-agg-name"); termsAgg.DocCountErrorUpperBound.Should().Be(10); termsAgg.SumOtherDocCount.Should().Be(200); termsAgg.Buckets.Should().HaveCount(2); @@ -79,7 +79,7 @@ public void CanDeserialize_BasicDoubleTermsAggregate() search.Aggregations.Should().HaveCount(1); - var termsAgg = search.Aggregations.DoubleTerms("my-agg-name"); + var termsAgg = search.Aggregations.GetDoubleTerms("my-agg-name"); termsAgg.DocCountErrorUpperBound.Should().Be(10); termsAgg.SumOtherDocCount.Should().Be(200); termsAgg.Buckets.Should().HaveCount(2); @@ -110,7 +110,7 @@ public void CanDeserialize_StringBased_MultiTermsAggregate() search.Aggregations.Should().HaveCount(1); - var termsAgg = search.Aggregations.MultiTerms("my-agg-name"); + var termsAgg = search.Aggregations.GetMultiTerms("my-agg-name"); termsAgg.DocCountErrorUpperBound.Should().Be(10); termsAgg.SumOtherDocCount.Should().Be(200); diff --git a/v7 b/v7 new file mode 160000 index 00000000000..f4dcd1e0711 --- /dev/null +++ b/v7 @@ -0,0 +1 @@ +Subproject commit f4dcd1e07110746e378757d70686638f08c925d6