The Geo Bounds Aggregation is a metric aggregation in Elasticsearch that computes the bounding box containing all geo_point and geo_shape values for a field. It's useful for determining the geographical extent of a set of locations.
Syntax
{
"aggs": {
"geo_bounds_name": {
"geo_bounds": {
"field": "location"
}
}
}
}
For more details, refer to the official Elasticsearch documentation.
Example Usage
GET /my-index/_search
{
"size": 0,
"aggs": {
"viewport": {
"geo_bounds": {
"field": "location",
"wrap_longitude": true
}
}
}
}
This query will return the bounding box for all locations in the "location" field.
Common Issues
- Ensure that the field specified is of type
geo_point
orgeo_shape
. - Be aware that the
wrap_longitude
parameter (default: false) affects how the bounding box is calculated when it crosses the antimeridian.
Best Practices
- Use
wrap_longitude: true
when dealing with global data to handle cases where the bounding box crosses the antimeridian. - Combine with other geo aggregations for more complex geospatial analysis.
- Consider using
geo_bounds
aggregation as a preliminary step before applying more specific geo filters or aggregations.
Frequently Asked Questions
Q: What's the difference between geo_bounds and geo_bounding_box?
A: Geo_bounds is an aggregation that calculates the bounding box containing all geo points in a result set, while geo_bounding_box is a query used to filter documents based on a predefined bounding box.
Q: Can geo_bounds aggregation work with geo_shape fields?
A: Yes, geo_bounds aggregation can work with both geo_point and geo_shape field types.
Q: How does the wrap_longitude parameter affect the results?
A: When wrap_longitude is set to true, the bounding box can "wrap" around the globe, which is useful for datasets that cross the antimeridian (180th meridian).
Q: Is there a performance impact when using geo_bounds on large datasets?
A: Geo_bounds aggregation is generally efficient, but like all aggregations, it can impact performance on very large datasets. Consider using sampling or filtering if performance becomes an issue.
Q: Can I use geo_bounds aggregation in a nested aggregation?
A: Yes, you can use geo_bounds as part of a nested aggregation to compute bounding boxes for subsets of your data.