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 Bounds Aggregation Usage
editGeo Bounds Aggregation Usage
editFluent DSL example
edits => s .Aggregations(a => a .GeoBounds("viewport", gb => gb .Field(p => p.Location) .WrapLongitude(true) ) )
Object Initializer syntax example
editnew SearchRequest<Project> { Aggregations = new GeoBoundsAggregation("viewport", Field<Project>(p => p.Location)) { WrapLongitude = true } }
Example json output.
{ "aggs": { "viewport": { "geo_bounds": { "field": "location", "wrap_longitude": true } } } }
Handling Responses
editresponse.ShouldBeValid(); var viewport = response.Aggs.GeoBounds("viewport"); viewport.Should().NotBeNull(); viewport.Bounds.Should().NotBeNull(); var bottomRight = viewport.Bounds.BottomRight; bottomRight.Should().NotBeNull(); bottomRight.Lat.Should().HaveValue(); GeoLocation.IsValidLatitude(bottomRight.Lat.Value).Should().BeTrue(); bottomRight.Lon.Should().HaveValue(); GeoLocation.IsValidLongitude(bottomRight.Lon.Value).Should().BeTrue(); var topLeft = viewport.Bounds.TopLeft; topLeft.Should().NotBeNull(); topLeft.Lat.Should().HaveValue(); GeoLocation.IsValidLatitude(topLeft.Lat.Value).Should().BeTrue(); topLeft.Lon.Should().HaveValue(); GeoLocation.IsValidLongitude(topLeft.Lon.Value).Should().BeTrue();