A geo_bounding_box query finds locations inside a rectangular geographic area. For example, a restaurant search can return venues between the rectangle’s top-left and bottom-right coordinates, while excluding locations outside it. section 12.1.1 section 12.4
Listing 12.6 Matching restaurant locations in a georectangle
GET restaurants/_search
{
"query": {
"geo_bounding_box": { #1
"location": { #2
"top_left": { #3
"lat": 52,
"lon": 0.2
},
"bottom_right": { #4
"lat": 49,
"lon": 0.1
}
}
}
}
}
Use the query against a geo_point field such as location. Set top_left and bottom_right to longitude-and-latitude coordinates that define the rectangle. section 12.4
The indexed field must contain geospatial data, commonly through a geo_point mapping. The rectangle’s corner names matter: their coordinates must describe a valid top-left and bottom-right boundary. The query can also use top_right and bottom_left, or separate top, left, bottom, and right values. section 4.6.1 section 12.4
Finding restaurants in central London
A restaurants index can store Sticky Fingers at address {"lon":"0.1278", "lat":"51.5074"}. A geo_bounding_box from top_left {"lon":"0", "lat":"52"} to bottom_right {"lon":"1", "lat":"50"} matches it because the restaurant falls inside the rectangle. Location values may also use arrays, strings, geohashes, or WKT; check the expected coordinate order for each format. section 4.6.1 section 12.4
