Skip to content

Commit 820475b

Browse files
authored
Add support for geo metric aggregations. (#7530)
* Generate geo metric aggregations * Add tests
1 parent 1ad2626 commit 820475b

30 files changed

+2223
-63
lines changed

exclusion.dic

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ asciidocs
66
yyyy
77
enum
88
trippable
9-
geotile
9+
geotile
10+
yaml

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

+20-20
Original file line numberDiff line numberDiff line change
@@ -256,26 +256,26 @@ public static void ReadAggregate(ref Utf8JsonReader reader, JsonSerializerOption
256256
break;
257257
}
258258

259-
//case "geo_bounds":
260-
// {
261-
// var agg = JsonSerializer.Deserialize<GeoBoundsAggregate>(ref reader, options);
262-
// dictionary.Add(nameParts[1], agg);
263-
// break;
264-
// }
265-
266-
//case "geo_centroid":
267-
// {
268-
// var agg = JsonSerializer.Deserialize<GeoCentroidAggregate>(ref reader, options);
269-
// dictionary.Add(nameParts[1], agg);
270-
// break;
271-
// }
272-
273-
//case "geo_line":
274-
// {
275-
// var agg = JsonSerializer.Deserialize<GeoLineAggregate>(ref reader, options);
276-
// dictionary.Add(nameParts[1], agg);
277-
// break;
278-
// }
259+
case "geo_bounds":
260+
{
261+
var agg = JsonSerializer.Deserialize<GeoBoundsAggregate>(ref reader, options);
262+
dictionary.Add(nameParts[1], agg);
263+
break;
264+
}
265+
266+
case "geo_centroid":
267+
{
268+
var agg = JsonSerializer.Deserialize<GeoCentroidAggregate>(ref reader, options);
269+
dictionary.Add(nameParts[1], agg);
270+
break;
271+
}
272+
273+
case "geo_line":
274+
{
275+
var agg = JsonSerializer.Deserialize<GeoLineAggregate>(ref reader, options);
276+
dictionary.Add(nameParts[1], agg);
277+
break;
278+
}
279279

280280
case "srareterms":
281281
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Elastic.Clients.Elasticsearch;
6+
7+
public partial class GeoLocation
8+
{
9+
public static bool IsValidLatitude(double latitude) => latitude >= -90 && latitude <= 90;
10+
public static bool IsValidLongitude(double longitude) => longitude >= -180 && longitude <= 180;
11+
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public AggregateDictionary(IReadOnlyDictionary<string, IAggregate> backingDictio
5252
public Elastic.Clients.Elasticsearch.Aggregations.StatsBucketAggregate? GetStatsBucket(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.StatsBucketAggregate?>(key);
5353
public Elastic.Clients.Elasticsearch.Aggregations.ExtendedStatsAggregate? GetExtendedStats(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.ExtendedStatsAggregate?>(key);
5454
public Elastic.Clients.Elasticsearch.Aggregations.ExtendedStatsBucketAggregate? GetExtendedStatsBucket(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.ExtendedStatsBucketAggregate?>(key);
55+
public Elastic.Clients.Elasticsearch.Aggregations.GeoBoundsAggregate? GetGeoBounds(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.GeoBoundsAggregate?>(key);
56+
public Elastic.Clients.Elasticsearch.Aggregations.GeoCentroidAggregate? GetGeoCentroid(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.GeoCentroidAggregate?>(key);
5557
public Elastic.Clients.Elasticsearch.Aggregations.HistogramAggregate? GetHistogram(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.HistogramAggregate?>(key);
5658
public Elastic.Clients.Elasticsearch.Aggregations.DateHistogramAggregate? GetDateHistogram(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.DateHistogramAggregate?>(key);
5759
public Elastic.Clients.Elasticsearch.Aggregations.AutoDateHistogramAggregate? GetAutoDateHistogram(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.AutoDateHistogramAggregate?>(key);
@@ -91,5 +93,6 @@ public AggregateDictionary(IReadOnlyDictionary<string, IAggregate> backingDictio
9193
public Elastic.Clients.Elasticsearch.Aggregations.RateAggregate? GetRate(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.RateAggregate?>(key);
9294
public Elastic.Clients.Elasticsearch.Aggregations.CumulativeCardinalityAggregate? GetCumulativeCardinality(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.CumulativeCardinalityAggregate?>(key);
9395
public Elastic.Clients.Elasticsearch.Aggregations.MatrixStatsAggregate? GetMatrixStats(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.MatrixStatsAggregate?>(key);
96+
public Elastic.Clients.Elasticsearch.Aggregations.GeoLineAggregate? GetGeoLine(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.GeoLineAggregate?>(key);
9497
private TAggregate TryGet<TAggregate>(string key) where TAggregate : class, IAggregate => BackingDictionary.TryGetValue(key, out var agg) ? agg as TAggregate : null;
9598
}

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

+60
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,26 @@ public override Aggregation Read(ref Utf8JsonReader reader, Type typeToConvert,
132132
return AggregationSerializationHelper.ReadContainer<Elastic.Clients.Elasticsearch.Aggregations.FiltersAggregation?>("filters", ref reader, options);
133133
}
134134

135+
if (propertyName == "geo_bounds")
136+
{
137+
return AggregationSerializationHelper.ReadContainer<Elastic.Clients.Elasticsearch.Aggregations.GeoBoundsAggregation?>("geo_bounds", ref reader, options);
138+
}
139+
140+
if (propertyName == "geo_centroid")
141+
{
142+
return AggregationSerializationHelper.ReadContainer<Elastic.Clients.Elasticsearch.Aggregations.GeoCentroidAggregation?>("geo_centroid", ref reader, options);
143+
}
144+
135145
if (propertyName == "geo_distance")
136146
{
137147
return AggregationSerializationHelper.ReadContainer<Elastic.Clients.Elasticsearch.Aggregations.GeoDistanceAggregation?>("geo_distance", ref reader, options);
138148
}
139149

150+
if (propertyName == "geo_line")
151+
{
152+
return AggregationSerializationHelper.ReadContainer<Elastic.Clients.Elasticsearch.Aggregations.GeoLineAggregation?>("geo_line", ref reader, options);
153+
}
154+
140155
if (propertyName == "geohash_grid")
141156
{
142157
return AggregationSerializationHelper.ReadContainer<Elastic.Clients.Elasticsearch.Aggregations.GeohashGridAggregation?>("geohash_grid", ref reader, options);
@@ -430,11 +445,26 @@ public AggregationDescriptor<TDocument> Filters(string name, Action<FiltersAggre
430445
return SetContainer(name, Aggregation.CreateWithAction("filters", configure));
431446
}
432447

448+
public AggregationDescriptor<TDocument> GeoBounds(string name, Action<GeoBoundsAggregationDescriptor<TDocument>> configure)
449+
{
450+
return SetContainer(name, Aggregation.CreateWithAction("geo_bounds", configure));
451+
}
452+
453+
public AggregationDescriptor<TDocument> GeoCentroid(string name, Action<GeoCentroidAggregationDescriptor<TDocument>> configure)
454+
{
455+
return SetContainer(name, Aggregation.CreateWithAction("geo_centroid", configure));
456+
}
457+
433458
public AggregationDescriptor<TDocument> GeoDistance(string name, Action<GeoDistanceAggregationDescriptor<TDocument>> configure)
434459
{
435460
return SetContainer(name, Aggregation.CreateWithAction("geo_distance", configure));
436461
}
437462

463+
public AggregationDescriptor<TDocument> GeoLine(string name, Action<GeoLineAggregationDescriptor<TDocument>> configure)
464+
{
465+
return SetContainer(name, Aggregation.CreateWithAction("geo_line", configure));
466+
}
467+
438468
public AggregationDescriptor<TDocument> GeohashGrid(string name, Action<GeohashGridAggregationDescriptor<TDocument>> configure)
439469
{
440470
return SetContainer(name, Aggregation.CreateWithAction("geohash_grid", configure));
@@ -769,6 +799,26 @@ public AggregationDescriptor Filters<TDocument>(string name, Action<FiltersAggre
769799
return SetContainer(name, Aggregation.CreateWithAction("filters", configure));
770800
}
771801

802+
public AggregationDescriptor GeoBounds(string name, Action<GeoBoundsAggregationDescriptor> configure)
803+
{
804+
return SetContainer(name, Aggregation.CreateWithAction("geo_bounds", configure));
805+
}
806+
807+
public AggregationDescriptor GeoBounds<TDocument>(string name, Action<GeoBoundsAggregationDescriptor<TDocument>> configure)
808+
{
809+
return SetContainer(name, Aggregation.CreateWithAction("geo_bounds", configure));
810+
}
811+
812+
public AggregationDescriptor GeoCentroid(string name, Action<GeoCentroidAggregationDescriptor> configure)
813+
{
814+
return SetContainer(name, Aggregation.CreateWithAction("geo_centroid", configure));
815+
}
816+
817+
public AggregationDescriptor GeoCentroid<TDocument>(string name, Action<GeoCentroidAggregationDescriptor<TDocument>> configure)
818+
{
819+
return SetContainer(name, Aggregation.CreateWithAction("geo_centroid", configure));
820+
}
821+
772822
public AggregationDescriptor GeoDistance(string name, Action<GeoDistanceAggregationDescriptor> configure)
773823
{
774824
return SetContainer(name, Aggregation.CreateWithAction("geo_distance", configure));
@@ -779,6 +829,16 @@ public AggregationDescriptor GeoDistance<TDocument>(string name, Action<GeoDista
779829
return SetContainer(name, Aggregation.CreateWithAction("geo_distance", configure));
780830
}
781831

832+
public AggregationDescriptor GeoLine(string name, Action<GeoLineAggregationDescriptor> configure)
833+
{
834+
return SetContainer(name, Aggregation.CreateWithAction("geo_line", configure));
835+
}
836+
837+
public AggregationDescriptor GeoLine<TDocument>(string name, Action<GeoLineAggregationDescriptor<TDocument>> configure)
838+
{
839+
return SetContainer(name, Aggregation.CreateWithAction("geo_line", configure));
840+
}
841+
782842
public AggregationDescriptor GeohashGrid(string name, Action<GeohashGridAggregationDescriptor> configure)
783843
{
784844
return SetContainer(name, Aggregation.CreateWithAction("geohash_grid", configure));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
//
5+
// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
6+
// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
7+
// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗
8+
// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝
9+
// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗
10+
// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
11+
// ------------------------------------------------
12+
//
13+
// This file is automatically generated.
14+
// Please do not edit these files manually.
15+
//
16+
// ------------------------------------------------
17+
18+
#nullable restore
19+
20+
using Elastic.Clients.Elasticsearch.Fluent;
21+
using Elastic.Clients.Elasticsearch.Serialization;
22+
using System;
23+
using System.Collections.Generic;
24+
using System.Linq.Expressions;
25+
using System.Text.Json;
26+
using System.Text.Json.Serialization;
27+
28+
namespace Elastic.Clients.Elasticsearch.Aggregations;
29+
30+
public sealed partial class GeoBoundsAggregate : IAggregate
31+
{
32+
[JsonInclude, JsonPropertyName("bounds")]
33+
public Elastic.Clients.Elasticsearch.GeoBounds? Bounds { get; init; }
34+
[JsonInclude, JsonPropertyName("meta")]
35+
public IReadOnlyDictionary<string, object>? Meta { get; init; }
36+
}

0 commit comments

Comments
 (0)