A georectangle defines a rectangular geographic area from the coordinates of its top-left and bottom-right corners. Each corner uses longitude and latitude values, allowing location searches to target a surrounding area such as central London. section 12.1.1
Searching restaurants inside a rectangle
Elasticsearch can use a geo_bounding_box query to return restaurant documents whose locations intersect the rectangle. The query identifies the location field, then supplies top_left and bottom_right coordinates. Restaurants inside the boundary are returned; others are excluded. 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
}
}
}
}
}
Inspect a complete REST request that searches the restaurants index with top_left and bottom_right coordinates. section 12.4
A georectangle can be expressed in several equivalent ways:
- Use top_left and bottom_right as the corner names. section 12.4
- Use top_right and bottom_left instead, or describe the boundaries as top, left, bottom, and right. section 12.4
- Represent geopoint corners as coordinate arrays or represent the rectangle with WKT. section 12.4
- Apply the same geo_bounding_box query pattern to geo_shape data by targeting the appropriate index. section 12.4
