Skip to content

[Backport 8.1] Add support for geo metric aggregations. #7531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion exclusion.dic
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ asciidocs
yyyy
enum
trippable
geotile
geotile
yaml
Original file line number Diff line number Diff line change
Expand Up @@ -256,26 +256,26 @@ public static void ReadAggregate(ref Utf8JsonReader reader, JsonSerializerOption
break;
}

//case "geo_bounds":
// {
// var agg = JsonSerializer.Deserialize<GeoBoundsAggregate>(ref reader, options);
// dictionary.Add(nameParts[1], agg);
// break;
// }

//case "geo_centroid":
// {
// var agg = JsonSerializer.Deserialize<GeoCentroidAggregate>(ref reader, options);
// dictionary.Add(nameParts[1], agg);
// break;
// }

//case "geo_line":
// {
// var agg = JsonSerializer.Deserialize<GeoLineAggregate>(ref reader, options);
// dictionary.Add(nameParts[1], agg);
// break;
// }
case "geo_bounds":
{
var agg = JsonSerializer.Deserialize<GeoBoundsAggregate>(ref reader, options);
dictionary.Add(nameParts[1], agg);
break;
}

case "geo_centroid":
{
var agg = JsonSerializer.Deserialize<GeoCentroidAggregate>(ref reader, options);
dictionary.Add(nameParts[1], agg);
break;
}

case "geo_line":
{
var agg = JsonSerializer.Deserialize<GeoLineAggregate>(ref reader, options);
dictionary.Add(nameParts[1], agg);
break;
}

case "srareterms":
{
Expand Down
11 changes: 11 additions & 0 deletions src/Elastic.Clients.Elasticsearch/Types/GeoLocation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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.

namespace Elastic.Clients.Elasticsearch;

public partial class GeoLocation
{
public static bool IsValidLatitude(double latitude) => latitude >= -90 && latitude <= 90;
public static bool IsValidLongitude(double longitude) => longitude >= -180 && longitude <= 180;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public AggregateDictionary(IReadOnlyDictionary<string, IAggregate> backingDictio
public Elastic.Clients.Elasticsearch.Aggregations.StatsBucketAggregate? GetStatsBucket(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.StatsBucketAggregate?>(key);
public Elastic.Clients.Elasticsearch.Aggregations.ExtendedStatsAggregate? GetExtendedStats(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.ExtendedStatsAggregate?>(key);
public Elastic.Clients.Elasticsearch.Aggregations.ExtendedStatsBucketAggregate? GetExtendedStatsBucket(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.ExtendedStatsBucketAggregate?>(key);
public Elastic.Clients.Elasticsearch.Aggregations.GeoBoundsAggregate? GetGeoBounds(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.GeoBoundsAggregate?>(key);
public Elastic.Clients.Elasticsearch.Aggregations.GeoCentroidAggregate? GetGeoCentroid(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.GeoCentroidAggregate?>(key);
public Elastic.Clients.Elasticsearch.Aggregations.HistogramAggregate? GetHistogram(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.HistogramAggregate?>(key);
public Elastic.Clients.Elasticsearch.Aggregations.DateHistogramAggregate? GetDateHistogram(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.DateHistogramAggregate?>(key);
public Elastic.Clients.Elasticsearch.Aggregations.AutoDateHistogramAggregate? GetAutoDateHistogram(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.AutoDateHistogramAggregate?>(key);
Expand Down Expand Up @@ -91,5 +93,6 @@ public AggregateDictionary(IReadOnlyDictionary<string, IAggregate> backingDictio
public Elastic.Clients.Elasticsearch.Aggregations.RateAggregate? GetRate(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.RateAggregate?>(key);
public Elastic.Clients.Elasticsearch.Aggregations.CumulativeCardinalityAggregate? GetCumulativeCardinality(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.CumulativeCardinalityAggregate?>(key);
public Elastic.Clients.Elasticsearch.Aggregations.MatrixStatsAggregate? GetMatrixStats(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.MatrixStatsAggregate?>(key);
public Elastic.Clients.Elasticsearch.Aggregations.GeoLineAggregate? GetGeoLine(string key) => TryGet<Elastic.Clients.Elasticsearch.Aggregations.GeoLineAggregate?>(key);
private TAggregate TryGet<TAggregate>(string key) where TAggregate : class, IAggregate => BackingDictionary.TryGetValue(key, out var agg) ? agg as TAggregate : null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,26 @@ public override Aggregation Read(ref Utf8JsonReader reader, Type typeToConvert,
return AggregationSerializationHelper.ReadContainer<Elastic.Clients.Elasticsearch.Aggregations.FiltersAggregation?>("filters", ref reader, options);
}

if (propertyName == "geo_bounds")
{
return AggregationSerializationHelper.ReadContainer<Elastic.Clients.Elasticsearch.Aggregations.GeoBoundsAggregation?>("geo_bounds", ref reader, options);
}

if (propertyName == "geo_centroid")
{
return AggregationSerializationHelper.ReadContainer<Elastic.Clients.Elasticsearch.Aggregations.GeoCentroidAggregation?>("geo_centroid", ref reader, options);
}

if (propertyName == "geo_distance")
{
return AggregationSerializationHelper.ReadContainer<Elastic.Clients.Elasticsearch.Aggregations.GeoDistanceAggregation?>("geo_distance", ref reader, options);
}

if (propertyName == "geo_line")
{
return AggregationSerializationHelper.ReadContainer<Elastic.Clients.Elasticsearch.Aggregations.GeoLineAggregation?>("geo_line", ref reader, options);
}

if (propertyName == "geohash_grid")
{
return AggregationSerializationHelper.ReadContainer<Elastic.Clients.Elasticsearch.Aggregations.GeohashGridAggregation?>("geohash_grid", ref reader, options);
Expand Down Expand Up @@ -430,11 +445,26 @@ public AggregationDescriptor<TDocument> Filters(string name, Action<FiltersAggre
return SetContainer(name, Aggregation.CreateWithAction("filters", configure));
}

public AggregationDescriptor<TDocument> GeoBounds(string name, Action<GeoBoundsAggregationDescriptor<TDocument>> configure)
{
return SetContainer(name, Aggregation.CreateWithAction("geo_bounds", configure));
}

public AggregationDescriptor<TDocument> GeoCentroid(string name, Action<GeoCentroidAggregationDescriptor<TDocument>> configure)
{
return SetContainer(name, Aggregation.CreateWithAction("geo_centroid", configure));
}

public AggregationDescriptor<TDocument> GeoDistance(string name, Action<GeoDistanceAggregationDescriptor<TDocument>> configure)
{
return SetContainer(name, Aggregation.CreateWithAction("geo_distance", configure));
}

public AggregationDescriptor<TDocument> GeoLine(string name, Action<GeoLineAggregationDescriptor<TDocument>> configure)
{
return SetContainer(name, Aggregation.CreateWithAction("geo_line", configure));
}

public AggregationDescriptor<TDocument> GeohashGrid(string name, Action<GeohashGridAggregationDescriptor<TDocument>> configure)
{
return SetContainer(name, Aggregation.CreateWithAction("geohash_grid", configure));
Expand Down Expand Up @@ -769,6 +799,26 @@ public AggregationDescriptor Filters<TDocument>(string name, Action<FiltersAggre
return SetContainer(name, Aggregation.CreateWithAction("filters", configure));
}

public AggregationDescriptor GeoBounds(string name, Action<GeoBoundsAggregationDescriptor> configure)
{
return SetContainer(name, Aggregation.CreateWithAction("geo_bounds", configure));
}

public AggregationDescriptor GeoBounds<TDocument>(string name, Action<GeoBoundsAggregationDescriptor<TDocument>> configure)
{
return SetContainer(name, Aggregation.CreateWithAction("geo_bounds", configure));
}

public AggregationDescriptor GeoCentroid(string name, Action<GeoCentroidAggregationDescriptor> configure)
{
return SetContainer(name, Aggregation.CreateWithAction("geo_centroid", configure));
}

public AggregationDescriptor GeoCentroid<TDocument>(string name, Action<GeoCentroidAggregationDescriptor<TDocument>> configure)
{
return SetContainer(name, Aggregation.CreateWithAction("geo_centroid", configure));
}

public AggregationDescriptor GeoDistance(string name, Action<GeoDistanceAggregationDescriptor> configure)
{
return SetContainer(name, Aggregation.CreateWithAction("geo_distance", configure));
Expand All @@ -779,6 +829,16 @@ public AggregationDescriptor GeoDistance<TDocument>(string name, Action<GeoDista
return SetContainer(name, Aggregation.CreateWithAction("geo_distance", configure));
}

public AggregationDescriptor GeoLine(string name, Action<GeoLineAggregationDescriptor> configure)
{
return SetContainer(name, Aggregation.CreateWithAction("geo_line", configure));
}

public AggregationDescriptor GeoLine<TDocument>(string name, Action<GeoLineAggregationDescriptor<TDocument>> configure)
{
return SetContainer(name, Aggregation.CreateWithAction("geo_line", configure));
}

public AggregationDescriptor GeohashGrid(string name, Action<GeohashGridAggregationDescriptor> configure)
{
return SetContainer(name, Aggregation.CreateWithAction("geohash_grid", configure));
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
//
// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗
// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝
// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗
// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Aggregations;

public sealed partial class GeoBoundsAggregate : IAggregate
{
[JsonInclude, JsonPropertyName("bounds")]
public Elastic.Clients.Elasticsearch.GeoBounds? Bounds { get; init; }
[JsonInclude, JsonPropertyName("meta")]
public IReadOnlyDictionary<string, object>? Meta { get; init; }
}
Loading