Skip to the workspace
Pebellslearn by building
Data Types  ›  Lesson

Geo Points — Searching by Place

Geo Points 12 minA geo_point must be mapped explicitly, and while objects and strings list latitude first, arrays and WKT list longitude first.

elasticsearch / Geo Points — Searching by Place

Explore each scene at your own pace.

01 · The rule

The rule

Geo Points — Searching by Place

The bookshop opens branches, and each book listing now records which branch has it on the shelf. A shopper in Pune asks, "which in-stock copies are within 10 km of me, nearest first?" That needs a field that understands latitude and longitude: geo_point.

The rule

Map it as geo_point first; in arrays, longitude comes first.

A geo_point holds one location on Earth. Dynamic mapping will not detect one — {"lat": 18.52, "lon": 73.86} would just become an object with two float fields — so you declare it:

PUT /books/_mapping
{ "properties": { "shop_location": { "type": "geo_point" } } }

It accepts several spellings of the same point:

Format Example (a Pune branch)
Object { "lat": 18.52, "lon": 73.86 }
String "18.52,73.86" — latitude, then longitude
Array [73.86, 18.52] — longitude, then latitude
WKT "POINT (73.86 18.52)" — longitude, then latitude

The array and WKT forms follow the GeoJSON convention of x before y, which is longitude before latitude. The object form is the safest because it names each part.

With the field mapped, you can filter by distance:

GET /books/_search
{
  "query": {
    "geo_distance": {
      "distance": "10km",
      "shop_location": { "lat": 18.53, "lon": 73.85 }
    }
  }
}

Other common tools: geo_bounding_box (everything inside a rectangle on the map), sorting by _geo_distance to put the nearest first, and aggregations that bucket results into distance rings or map tiles.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.