liveBook · Manning

Georectangle

As explained in Elasticsearch in Action, Second Edition

A georectangle is a rectangular geographic boundary defined by the coordinates of its top-left and bottom-right corners.

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

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Defines corner coordinates and demonstrates query forms, while deferring the detailed mechanics of geo_bounding_box execution.
Examples
Demonstrates central London, restaurants, cafes, Imperial College London, coordinate arrays, and WKT rectangle representations.
What it assumes
Assumes geographic coordinates and location fields, while introducing rectangular boundaries through concrete search scenarios.
What you can do after
Apply Elasticsearch geo_bounding_box queries to retrieve locations intersecting a rectangle.
How it connects
Connects geographic boundaries with geo_bounding_box queries, geo_point fields, geo_shape fields, latitude, and longitude.

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.