WARNING: Version 5.x has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Geo Distance Aggregation Usage
editGeo Distance Aggregation Usage
editFluent DSL example
edits => s .Aggregations(a => a .GeoDistance("rings_around_amsterdam", g => g .Field(p => p.Location) .Origin(52.376, 4.894) .Ranges( r => r.To(100), r => r.From(100).To(300), r => r.From(300) ) ) )
Object Initializer syntax example
editnew SearchRequest<Project> { Aggregations = new GeoDistanceAggregation("rings_around_amsterdam") { Field = Field((Project p) => p.Location), Origin = "52.376, 4.894", Ranges = new List<AggregationRange> { new AggregationRange { To = 100 }, new AggregationRange { From = 100, To = 300 }, new AggregationRange { From = 300 } } } }
Example json output.
{ "aggs": { "rings_around_amsterdam": { "geo_distance": { "field": "location", "origin": { "lat": 52.376, "lon": 4.894 }, "ranges": [ { "to": 100.0 }, { "from": 100.0, "to": 300.0 }, { "from": 300.0 } ] } } } }
Handling Responses
editresponse.ShouldBeValid(); var ringsAroundAmsterdam = response.Aggs.GeoDistance("rings_around_amsterdam"); ringsAroundAmsterdam.Should().NotBeNull(); ringsAroundAmsterdam.Buckets.FirstOrDefault(r => r.Key == "*-100.0").Should().NotBeNull(); ringsAroundAmsterdam.Buckets.FirstOrDefault(r => r.Key == "100.0-300.0").Should().NotBeNull(); ringsAroundAmsterdam.Buckets.FirstOrDefault(r => r.Key == "300.0-*").Should().NotBeNull();