Skip to content

Commit 12c7694

Browse files
stevejgordongithub-actions[bot]
authored andcommitted
Support sub-aggs for single bucket aggregations (#6633)
* Aggregates implement IAggregate * Response to schema changes * Remove Aggregate class * Fix single bucket aggregate types
1 parent 8e9901f commit 12c7694

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+472
-81
lines changed

src/Elastic.Clients.Elasticsearch/Common/Aggregations/Aggregate.cs renamed to src/Elastic.Clients.Elasticsearch/Common/Aggregations/IAggregate.cs

-9
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,3 @@
55
namespace Elastic.Clients.Elasticsearch.Aggregations;
66

77
public interface IAggregate { }
8-
9-
/// <summary>
10-
/// Base class for all aggregates.
11-
/// </summary>
12-
public abstract class Aggregate : IAggregate
13-
{
14-
}
15-
16-

src/Elastic.Clients.Elasticsearch/_Generated/Api/Snapshot/GetSnapshotRequest.g.cs

+7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public sealed class GetSnapshotRequestParameters : RequestParameters<GetSnapshot
3939
[JsonIgnore]
4040
public bool? IndexDetails { get => Q<bool?>("index_details"); set => Q("index_details", value); }
4141

42+
[JsonIgnore]
43+
public bool? IndexNames { get => Q<bool?>("index_names"); set => Q("index_names", value); }
44+
4245
[JsonIgnore]
4346
public bool? IncludeRepository { get => Q<bool?>("include_repository"); set => Q("include_repository", value); }
4447

@@ -85,6 +88,9 @@ public GetSnapshotRequest(Elastic.Clients.Elasticsearch.Name repository, Elastic
8588
[JsonIgnore]
8689
public bool? IndexDetails { get => Q<bool?>("index_details"); set => Q("index_details", value); }
8790

91+
[JsonIgnore]
92+
public bool? IndexNames { get => Q<bool?>("index_names"); set => Q("index_names", value); }
93+
8894
[JsonIgnore]
8995
public bool? IncludeRepository { get => Q<bool?>("include_repository"); set => Q("include_repository", value); }
9096

@@ -129,6 +135,7 @@ internal GetSnapshotRequestDescriptor()
129135
public GetSnapshotRequestDescriptor IgnoreUnavailable(bool? ignoreUnavailable = true) => Qs("ignore_unavailable", ignoreUnavailable);
130136
public GetSnapshotRequestDescriptor IncludeRepository(bool? includeRepository = true) => Qs("include_repository", includeRepository);
131137
public GetSnapshotRequestDescriptor IndexDetails(bool? indexDetails = true) => Qs("index_details", indexDetails);
138+
public GetSnapshotRequestDescriptor IndexNames(bool? indexNames = true) => Qs("index_names", indexNames);
132139
public GetSnapshotRequestDescriptor MasterTimeout(Elastic.Clients.Elasticsearch.Duration? masterTimeout) => Qs("master_timeout", masterTimeout);
133140
public GetSnapshotRequestDescriptor Offset(int? offset) => Qs("offset", offset);
134141
public GetSnapshotRequestDescriptor Order(Elastic.Clients.Elasticsearch.SortOrder? order) => Qs("order", order);

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AdjacencyMatrixAggregate.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class AdjacencyMatrixAggregate : Aggregate
27+
public sealed partial class AdjacencyMatrixAggregate : IAggregate
2828
{
2929
[JsonInclude]
3030
[JsonPropertyName("buckets")]

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AutoDateHistogramAggregate.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class AutoDateHistogramAggregate : Aggregate
27+
public sealed partial class AutoDateHistogramAggregate : IAggregate
2828
{
2929
[JsonInclude]
3030
[JsonPropertyName("buckets")]

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/AvgAggregate.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class AvgAggregate : Aggregate
27+
public sealed partial class AvgAggregate : IAggregate
2828
{
2929
[JsonInclude]
3030
[JsonPropertyName("meta")]

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/BoxPlotAggregate.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class BoxPlotAggregate : Aggregate
27+
public sealed partial class BoxPlotAggregate : IAggregate
2828
{
2929
[JsonInclude]
3030
[JsonPropertyName("lower")]

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CardinalityAggregate.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class CardinalityAggregate : Aggregate
27+
public sealed partial class CardinalityAggregate : IAggregate
2828
{
2929
[JsonInclude]
3030
[JsonPropertyName("meta")]

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/ChildrenAggregate.g.cs

+50-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class ChildrenAggregate : Aggregate
27+
[JsonConverter(typeof(ChildrenAggregateConverter))]
28+
public sealed partial class ChildrenAggregate : AggregateDictionary, IAggregate
2829
{
29-
[JsonInclude]
30-
[JsonPropertyName("aggregations")]
31-
public Elastic.Clients.Elasticsearch.Aggregations.AggregateDictionary Aggregations { get; init; }
30+
public ChildrenAggregate(IReadOnlyDictionary<string, IAggregate> backingDictionary) : base(backingDictionary)
31+
{
32+
}
3233

3334
[JsonInclude]
3435
[JsonPropertyName("doc_count")]
@@ -38,4 +39,49 @@ public sealed partial class ChildrenAggregate : Aggregate
3839
[JsonPropertyName("meta")]
3940
public Dictionary<string, object>? Meta { get; init; }
4041
}
42+
43+
internal sealed class ChildrenAggregateConverter : JsonConverter<ChildrenAggregate>
44+
{
45+
public override ChildrenAggregate? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
46+
{
47+
if (reader.TokenType != JsonTokenType.StartObject)
48+
throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}.");
49+
var subAggs = new Dictionary<string, IAggregate>(); // TODO - Optimise this and only create if we need it.
50+
long docCount = default;
51+
Dictionary<string, object>? meta = default;
52+
while (reader.Read())
53+
{
54+
if (reader.TokenType == JsonTokenType.EndObject)
55+
break;
56+
if (reader.TokenType != JsonTokenType.PropertyName)
57+
throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}.");
58+
var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those
59+
reader.Read();
60+
if (name.Equals("doc_count", StringComparison.Ordinal))
61+
{
62+
docCount = JsonSerializer.Deserialize<long>(ref reader, options);
63+
continue;
64+
}
65+
66+
if (name.Equals("meta", StringComparison.Ordinal))
67+
{
68+
meta = JsonSerializer.Deserialize<Dictionary<string, object>?>(ref reader, options);
69+
continue;
70+
}
71+
72+
if (name.Contains("#"))
73+
{
74+
AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name);
75+
continue;
76+
}
77+
78+
throw new JsonException("Unknown property read from JSON.");
79+
}
80+
81+
return new ChildrenAggregate(subAggs)
82+
{ DocCount = docCount, Meta = meta };
83+
}
84+
85+
public override void Write(Utf8JsonWriter writer, ChildrenAggregate value, JsonSerializerOptions options) => throw new NotImplementedException();
86+
}
4187
}

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CompositeAggregate.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class CompositeAggregate : Aggregate
27+
public sealed partial class CompositeAggregate : IAggregate
2828
{
2929
[JsonInclude]
3030
[JsonPropertyName("after_key")]

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/CumulativeCardinalityAggregate.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class CumulativeCardinalityAggregate : Aggregate
27+
public sealed partial class CumulativeCardinalityAggregate : IAggregate
2828
{
2929
[JsonInclude]
3030
[JsonPropertyName("meta")]

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DateHistogramAggregate.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class DateHistogramAggregate : Aggregate
27+
public sealed partial class DateHistogramAggregate : IAggregate
2828
{
2929
[JsonInclude]
3030
[JsonPropertyName("buckets")]

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DateRangeAggregate.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class DateRangeAggregate : Aggregate
27+
public sealed partial class DateRangeAggregate : IAggregate
2828
{
2929
[JsonInclude]
3030
[JsonPropertyName("buckets")]

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DerivativeAggregate.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class DerivativeAggregate : Aggregate
27+
public sealed partial class DerivativeAggregate : IAggregate
2828
{
2929
[JsonInclude]
3030
[JsonPropertyName("meta")]

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DoubleTermsAggregate.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class DoubleTermsAggregate : Aggregate
27+
public sealed partial class DoubleTermsAggregate : IAggregate
2828
{
2929
[JsonInclude]
3030
[JsonPropertyName("buckets")]

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/ExtendedStatsAggregate.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class ExtendedStatsAggregate : Aggregate
27+
public sealed partial class ExtendedStatsAggregate : IAggregate
2828
{
2929
[JsonInclude]
3030
[JsonPropertyName("avg")]

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/ExtendedStatsBucketAggregate.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class ExtendedStatsBucketAggregate : Aggregate
27+
public sealed partial class ExtendedStatsBucketAggregate : IAggregate
2828
{
2929
[JsonInclude]
3030
[JsonPropertyName("avg")]

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/FilterAggregate.g.cs

+50-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class FilterAggregate : Aggregate
27+
[JsonConverter(typeof(FilterAggregateConverter))]
28+
public sealed partial class FilterAggregate : AggregateDictionary, IAggregate
2829
{
29-
[JsonInclude]
30-
[JsonPropertyName("aggregations")]
31-
public Elastic.Clients.Elasticsearch.Aggregations.AggregateDictionary Aggregations { get; init; }
30+
public FilterAggregate(IReadOnlyDictionary<string, IAggregate> backingDictionary) : base(backingDictionary)
31+
{
32+
}
3233

3334
[JsonInclude]
3435
[JsonPropertyName("doc_count")]
@@ -38,4 +39,49 @@ public sealed partial class FilterAggregate : Aggregate
3839
[JsonPropertyName("meta")]
3940
public Dictionary<string, object>? Meta { get; init; }
4041
}
42+
43+
internal sealed class FilterAggregateConverter : JsonConverter<FilterAggregate>
44+
{
45+
public override FilterAggregate? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
46+
{
47+
if (reader.TokenType != JsonTokenType.StartObject)
48+
throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}.");
49+
var subAggs = new Dictionary<string, IAggregate>(); // TODO - Optimise this and only create if we need it.
50+
long docCount = default;
51+
Dictionary<string, object>? meta = default;
52+
while (reader.Read())
53+
{
54+
if (reader.TokenType == JsonTokenType.EndObject)
55+
break;
56+
if (reader.TokenType != JsonTokenType.PropertyName)
57+
throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}.");
58+
var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those
59+
reader.Read();
60+
if (name.Equals("doc_count", StringComparison.Ordinal))
61+
{
62+
docCount = JsonSerializer.Deserialize<long>(ref reader, options);
63+
continue;
64+
}
65+
66+
if (name.Equals("meta", StringComparison.Ordinal))
67+
{
68+
meta = JsonSerializer.Deserialize<Dictionary<string, object>?>(ref reader, options);
69+
continue;
70+
}
71+
72+
if (name.Contains("#"))
73+
{
74+
AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name);
75+
continue;
76+
}
77+
78+
throw new JsonException("Unknown property read from JSON.");
79+
}
80+
81+
return new FilterAggregate(subAggs)
82+
{ DocCount = docCount, Meta = meta };
83+
}
84+
85+
public override void Write(Utf8JsonWriter writer, FilterAggregate value, JsonSerializerOptions options) => throw new NotImplementedException();
86+
}
4187
}

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/FiltersAggregate.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class FiltersAggregate : Aggregate
27+
public sealed partial class FiltersAggregate : IAggregate
2828
{
2929
[JsonInclude]
3030
[JsonPropertyName("buckets")]

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/GlobalAggregate.g.cs

+50-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class GlobalAggregate : Aggregate
27+
[JsonConverter(typeof(GlobalAggregateConverter))]
28+
public sealed partial class GlobalAggregate : AggregateDictionary, IAggregate
2829
{
29-
[JsonInclude]
30-
[JsonPropertyName("aggregations")]
31-
public Elastic.Clients.Elasticsearch.Aggregations.AggregateDictionary Aggregations { get; init; }
30+
public GlobalAggregate(IReadOnlyDictionary<string, IAggregate> backingDictionary) : base(backingDictionary)
31+
{
32+
}
3233

3334
[JsonInclude]
3435
[JsonPropertyName("doc_count")]
@@ -38,4 +39,49 @@ public sealed partial class GlobalAggregate : Aggregate
3839
[JsonPropertyName("meta")]
3940
public Dictionary<string, object>? Meta { get; init; }
4041
}
42+
43+
internal sealed class GlobalAggregateConverter : JsonConverter<GlobalAggregate>
44+
{
45+
public override GlobalAggregate? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
46+
{
47+
if (reader.TokenType != JsonTokenType.StartObject)
48+
throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}.");
49+
var subAggs = new Dictionary<string, IAggregate>(); // TODO - Optimise this and only create if we need it.
50+
long docCount = default;
51+
Dictionary<string, object>? meta = default;
52+
while (reader.Read())
53+
{
54+
if (reader.TokenType == JsonTokenType.EndObject)
55+
break;
56+
if (reader.TokenType != JsonTokenType.PropertyName)
57+
throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}.");
58+
var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those
59+
reader.Read();
60+
if (name.Equals("doc_count", StringComparison.Ordinal))
61+
{
62+
docCount = JsonSerializer.Deserialize<long>(ref reader, options);
63+
continue;
64+
}
65+
66+
if (name.Equals("meta", StringComparison.Ordinal))
67+
{
68+
meta = JsonSerializer.Deserialize<Dictionary<string, object>?>(ref reader, options);
69+
continue;
70+
}
71+
72+
if (name.Contains("#"))
73+
{
74+
AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name);
75+
continue;
76+
}
77+
78+
throw new JsonException("Unknown property read from JSON.");
79+
}
80+
81+
return new GlobalAggregate(subAggs)
82+
{ DocCount = docCount, Meta = meta };
83+
}
84+
85+
public override void Write(Utf8JsonWriter writer, GlobalAggregate value, JsonSerializerOptions options) => throw new NotImplementedException();
86+
}
4187
}

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/HistogramAggregate.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class HistogramAggregate : Aggregate
27+
public sealed partial class HistogramAggregate : IAggregate
2828
{
2929
[JsonInclude]
3030
[JsonPropertyName("buckets")]

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/InferenceAggregate.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class InferenceAggregate : Aggregate
27+
public sealed partial class InferenceAggregate : IAggregate
2828
{
2929
[JsonInclude]
3030
[JsonPropertyName("data")]

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/IpRangeAggregate.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public sealed partial class IpRangeAggregate : Aggregate
27+
public sealed partial class IpRangeAggregate : IAggregate
2828
{
2929
[JsonInclude]
3030
[JsonPropertyName("buckets")]

0 commit comments

Comments
 (0)