liveBook · Manning

Geo_bounding_box query

As explained in Elasticsearch in Action, Second Edition

A geo_bounding_box query retrieves documents whose geographic points or shapes intersect a rectangular geographic boundary.

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

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Explains rectangle construction, query syntax, coordinate alternatives, and geo_shape reuse, but defers broader geospatial-query detail.
Examples
Uses London restaurants, Sticky Fingers, Imperial College London, array coordinates, and WKT bounding-box representations.
What it assumes
Assumes basic document search and geographic coordinates while introducing geo_point fields and multiple geopoint representations.
What you can do after
Apply it via Elasticsearch REST queries to retrieve documents intersecting a rectangle defined by geographic coordinates.
How it connects
Connects geo_point and geo_shape fields with geospatial queries, geo_distance queries, WKT, and Boolean filtering.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elasticsearch in Action, Second Edition. The section links point to the parts of the book it draws on.