IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Geo Centroid Aggregation Usage
editGeo Centroid Aggregation Usage
editA metric aggregation that computes the weighted centroid from all coordinate values for a Geo-point datatype field.
Be sure to read the Elasticsearch documentation on Geo Centroid Aggregation
Fluent DSL example
edita => a .GeoCentroid("centroid", gb => gb .Field(p => p.LocationPoint) )
Object Initializer syntax example
editnew GeoCentroidAggregation("centroid", Infer.Field<Project>(p => p.LocationPoint))
Example json output.
{ "centroid": { "geo_centroid": { "field": "locationPoint" } } }
Handling Responses
editresponse.ShouldBeValid(); var centroid = response.Aggregations.GeoCentroid("centroid"); centroid.Should().NotBeNull(); centroid.Count.Should().BeGreaterThan(0); centroid.Location.Should().NotBeNull(); centroid.Location.Latitude.Should().NotBe(0); centroid.Location.Longitude.Should().NotBe(0);
Geo Centroid Sub Aggregation
editThe geo_centroid
aggregation is more interesting when combined as a sub-aggregation to other bucket aggregations
Fluent DSL example
edita => a .Terms("projects", t => t .Field(p => p.Name) .Aggregations(sa => sa .GeoCentroid("centroid", gb => gb .Field(p => p.LocationPoint) ) ) )
Object Initializer syntax example
editnew TermsAggregation("projects") { Field = Infer.Field<Project>(p => p.Name), Aggregations = new GeoCentroidAggregation("centroid", Infer.Field<Project>(p => p.LocationPoint)) }
Example json output.
{ "projects": { "terms": { "field": "name" }, "aggs": { "centroid": { "geo_centroid": { "field": "locationPoint" } } } } }
Handling Responses
editresponse.ShouldBeValid(); var projects = response.Aggregations.Terms("projects"); foreach (var bucket in projects.Buckets) { var centroid = bucket.GeoCentroid("centroid"); centroid.Should().NotBeNull(); centroid.Count.Should().BeGreaterThan(0); centroid.Location.Should().NotBeNull(); centroid.Location.Latitude.Should().NotBe(0); centroid.Location.Longitude.Should().NotBe(0); }
Fluent DSL example
edita => a .GeoCentroid("centroid", gb => gb .Field(p => p.LocationPoint) )
Object Initializer syntax example
editnew GeoCentroidAggregation("centroid", Infer.Field<Project>(p => p.LocationPoint))
Example json output.
{ "centroid": { "geo_centroid": { "field": "locationPoint" } } }
Handling Responses
editresponse.ShouldBeValid(); var centroid = response.Aggregations.GeoCentroid("centroid"); centroid.Should().NotBeNull(); centroid.Count.Should().Be(0);