Skip to content

Commit 02b315d

Browse files
Regenerated buckets with support for sub-aggs (#6375) (#6376)
* Regenerated buckets with support for sub-aggs * Fix license header Co-authored-by: Steve Gordon <sgordon@hotmail.co.uk>
1 parent 64b4d72 commit 02b315d

36 files changed

+1523
-549
lines changed

src/Elastic.Clients.Elasticsearch/Types/Aggregations/AggregateDictionaryConverter.cs

Lines changed: 433 additions & 428 deletions
Large diffs are not rendered by default.

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

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,53 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public partial class AdjacencyMatrixBucket : MultiBucketBase
27+
[JsonConverter(typeof(AdjacencyMatrixBucketConverter))]
28+
public sealed partial class AdjacencyMatrixBucket : AggregateDictionary
2829
{
30+
public AdjacencyMatrixBucket(IReadOnlyDictionary<string, AggregateBase> backingDictionary) : base(backingDictionary)
31+
{
32+
}
33+
34+
[JsonInclude]
35+
[JsonPropertyName("doc_count")]
36+
public long DocCount { get; init; }
37+
}
38+
39+
internal sealed class AdjacencyMatrixBucketConverter : JsonConverter<AdjacencyMatrixBucket>
40+
{
41+
public override AdjacencyMatrixBucket? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
42+
{
43+
if (reader.TokenType != JsonTokenType.StartObject)
44+
throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}.");
45+
var subAggs = new Dictionary<string, AggregateBase>(); // TODO - Optimise this and only create if we need it.
46+
long docCount = default;
47+
while (reader.Read())
48+
{
49+
if (reader.TokenType == JsonTokenType.EndObject)
50+
break;
51+
if (reader.TokenType != JsonTokenType.PropertyName)
52+
throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}.");
53+
var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those
54+
reader.Read();
55+
if (name.Equals("doc_count", StringComparison.Ordinal))
56+
{
57+
docCount = JsonSerializer.Deserialize<long>(ref reader, options);
58+
continue;
59+
}
60+
61+
if (name.Contains("#"))
62+
{
63+
AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name);
64+
continue;
65+
}
66+
67+
throw new JsonException("Unknown property read from JSON.");
68+
}
69+
70+
return new AdjacencyMatrixBucket(subAggs)
71+
{ DocCount = docCount };
72+
}
73+
74+
public override void Write(Utf8JsonWriter writer, AdjacencyMatrixBucket value, JsonSerializerOptions options) => throw new NotImplementedException();
2975
}
3076
}

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

Lines changed: 47 additions & 47 deletions
Large diffs are not rendered by default.

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

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,64 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public partial class CompositeBucket : MultiBucketBase
27+
[JsonConverter(typeof(CompositeBucketConverter))]
28+
public sealed partial class CompositeBucket : AggregateDictionary
2829
{
30+
public CompositeBucket(IReadOnlyDictionary<string, AggregateBase> backingDictionary) : base(backingDictionary)
31+
{
32+
}
33+
34+
[JsonInclude]
35+
[JsonPropertyName("doc_count")]
36+
public long DocCount { get; init; }
37+
2938
[JsonInclude]
3039
[JsonPropertyName("key")]
3140
public Dictionary<string, object> Key { get; init; }
3241
}
42+
43+
internal sealed class CompositeBucketConverter : JsonConverter<CompositeBucket>
44+
{
45+
public override CompositeBucket? 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, AggregateBase>(); // TODO - Optimise this and only create if we need it.
50+
long docCount = default;
51+
Dictionary<string, object> key = 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("key", StringComparison.Ordinal))
67+
{
68+
key = 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 CompositeBucket(subAggs)
82+
{ DocCount = docCount, Key = key };
83+
}
84+
85+
public override void Write(Utf8JsonWriter writer, CompositeBucket value, JsonSerializerOptions options) => throw new NotImplementedException();
86+
}
3387
}

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

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,17 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public partial class DateHistogramBucket : MultiBucketBase
27+
[JsonConverter(typeof(DateHistogramBucketConverter))]
28+
public sealed partial class DateHistogramBucket : AggregateDictionary
2829
{
30+
public DateHistogramBucket(IReadOnlyDictionary<string, AggregateBase> backingDictionary) : base(backingDictionary)
31+
{
32+
}
33+
34+
[JsonInclude]
35+
[JsonPropertyName("doc_count")]
36+
public long DocCount { get; init; }
37+
2938
[JsonInclude]
3039
[JsonPropertyName("key")]
3140
public Elastic.Clients.Elasticsearch.EpochMillis Key { get; init; }
@@ -34,4 +43,56 @@ public partial class DateHistogramBucket : MultiBucketBase
3443
[JsonPropertyName("key_as_string")]
3544
public string? KeyAsString { get; init; }
3645
}
46+
47+
internal sealed class DateHistogramBucketConverter : JsonConverter<DateHistogramBucket>
48+
{
49+
public override DateHistogramBucket? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
50+
{
51+
if (reader.TokenType != JsonTokenType.StartObject)
52+
throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}.");
53+
var subAggs = new Dictionary<string, AggregateBase>(); // TODO - Optimise this and only create if we need it.
54+
long docCount = default;
55+
Elastic.Clients.Elasticsearch.EpochMillis key = default;
56+
string? keyAsString = default;
57+
while (reader.Read())
58+
{
59+
if (reader.TokenType == JsonTokenType.EndObject)
60+
break;
61+
if (reader.TokenType != JsonTokenType.PropertyName)
62+
throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}.");
63+
var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those
64+
reader.Read();
65+
if (name.Equals("doc_count", StringComparison.Ordinal))
66+
{
67+
docCount = JsonSerializer.Deserialize<long>(ref reader, options);
68+
continue;
69+
}
70+
71+
if (name.Equals("key", StringComparison.Ordinal))
72+
{
73+
key = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.EpochMillis>(ref reader, options);
74+
continue;
75+
}
76+
77+
if (name.Equals("key_as_string", StringComparison.Ordinal))
78+
{
79+
keyAsString = JsonSerializer.Deserialize<string?>(ref reader, options);
80+
continue;
81+
}
82+
83+
if (name.Contains("#"))
84+
{
85+
AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name);
86+
continue;
87+
}
88+
89+
throw new JsonException("Unknown property read from JSON.");
90+
}
91+
92+
return new DateHistogramBucket(subAggs)
93+
{ DocCount = docCount, Key = key, KeyAsString = keyAsString };
94+
}
95+
96+
public override void Write(Utf8JsonWriter writer, DateHistogramBucket value, JsonSerializerOptions options) => throw new NotImplementedException();
97+
}
3798
}

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

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,21 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public partial class DoubleTermsBucket : TermsBucketBase
27+
[JsonConverter(typeof(DoubleTermsBucketConverter))]
28+
public sealed partial class DoubleTermsBucket : AggregateDictionary
2829
{
30+
public DoubleTermsBucket(IReadOnlyDictionary<string, AggregateBase> backingDictionary) : base(backingDictionary)
31+
{
32+
}
33+
34+
[JsonInclude]
35+
[JsonPropertyName("doc_count")]
36+
public long DocCount { get; init; }
37+
38+
[JsonInclude]
39+
[JsonPropertyName("doc_count_error")]
40+
public long? DocCountError { get; init; }
41+
2942
[JsonInclude]
3043
[JsonPropertyName("key")]
3144
public double Key { get; init; }
@@ -34,4 +47,63 @@ public partial class DoubleTermsBucket : TermsBucketBase
3447
[JsonPropertyName("key_as_string")]
3548
public string? KeyAsString { get; init; }
3649
}
50+
51+
internal sealed class DoubleTermsBucketConverter : JsonConverter<DoubleTermsBucket>
52+
{
53+
public override DoubleTermsBucket? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
54+
{
55+
if (reader.TokenType != JsonTokenType.StartObject)
56+
throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}.");
57+
var subAggs = new Dictionary<string, AggregateBase>(); // TODO - Optimise this and only create if we need it.
58+
long docCount = default;
59+
long? docCountError = default;
60+
double key = default;
61+
string? keyAsString = default;
62+
while (reader.Read())
63+
{
64+
if (reader.TokenType == JsonTokenType.EndObject)
65+
break;
66+
if (reader.TokenType != JsonTokenType.PropertyName)
67+
throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}.");
68+
var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those
69+
reader.Read();
70+
if (name.Equals("doc_count", StringComparison.Ordinal))
71+
{
72+
docCount = JsonSerializer.Deserialize<long>(ref reader, options);
73+
continue;
74+
}
75+
76+
if (name.Equals("doc_count_error", StringComparison.Ordinal))
77+
{
78+
docCountError = JsonSerializer.Deserialize<long?>(ref reader, options);
79+
continue;
80+
}
81+
82+
if (name.Equals("key", StringComparison.Ordinal))
83+
{
84+
key = JsonSerializer.Deserialize<double>(ref reader, options);
85+
continue;
86+
}
87+
88+
if (name.Equals("key_as_string", StringComparison.Ordinal))
89+
{
90+
keyAsString = JsonSerializer.Deserialize<string?>(ref reader, options);
91+
continue;
92+
}
93+
94+
if (name.Contains("#"))
95+
{
96+
AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name);
97+
continue;
98+
}
99+
100+
throw new JsonException("Unknown property read from JSON.");
101+
}
102+
103+
return new DoubleTermsBucket(subAggs)
104+
{ DocCount = docCount, DocCountError = docCountError, Key = key, KeyAsString = keyAsString };
105+
}
106+
107+
public override void Write(Utf8JsonWriter writer, DoubleTermsBucket value, JsonSerializerOptions options) => throw new NotImplementedException();
108+
}
37109
}

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

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,53 @@
2424
#nullable restore
2525
namespace Elastic.Clients.Elasticsearch.Aggregations
2626
{
27-
public partial class FiltersBucket : MultiBucketBase
27+
[JsonConverter(typeof(FiltersBucketConverter))]
28+
public sealed partial class FiltersBucket : AggregateDictionary
2829
{
30+
public FiltersBucket(IReadOnlyDictionary<string, AggregateBase> backingDictionary) : base(backingDictionary)
31+
{
32+
}
33+
34+
[JsonInclude]
35+
[JsonPropertyName("doc_count")]
36+
public long DocCount { get; init; }
37+
}
38+
39+
internal sealed class FiltersBucketConverter : JsonConverter<FiltersBucket>
40+
{
41+
public override FiltersBucket? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
42+
{
43+
if (reader.TokenType != JsonTokenType.StartObject)
44+
throw new JsonException($"Expected {JsonTokenType.StartObject} but read {reader.TokenType}.");
45+
var subAggs = new Dictionary<string, AggregateBase>(); // TODO - Optimise this and only create if we need it.
46+
long docCount = default;
47+
while (reader.Read())
48+
{
49+
if (reader.TokenType == JsonTokenType.EndObject)
50+
break;
51+
if (reader.TokenType != JsonTokenType.PropertyName)
52+
throw new JsonException($"Expected {JsonTokenType.PropertyName} but read {reader.TokenType}.");
53+
var name = reader.GetString(); // TODO: Future optimisation, get raw bytes span and parse based on those
54+
reader.Read();
55+
if (name.Equals("doc_count", StringComparison.Ordinal))
56+
{
57+
docCount = JsonSerializer.Deserialize<long>(ref reader, options);
58+
continue;
59+
}
60+
61+
if (name.Contains("#"))
62+
{
63+
AggregateDictionaryConverter.ReadAggregate(ref reader, options, subAggs, name);
64+
continue;
65+
}
66+
67+
throw new JsonException("Unknown property read from JSON.");
68+
}
69+
70+
return new FiltersBucket(subAggs)
71+
{ DocCount = docCount };
72+
}
73+
74+
public override void Write(Utf8JsonWriter writer, FiltersBucket value, JsonSerializerOptions options) => throw new NotImplementedException();
2975
}
3076
}

0 commit comments

Comments
 (0)