0
0
Elasticsearchquery~3 mins

Why Geo-point and geo-shape types in Elasticsearch? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could find any place nearby in seconds without checking every address yourself?

The Scenario

Imagine you have a huge list of addresses and you want to find all places within 5 miles of your home. Doing this by hand means checking each address one by one on a map.

The Problem

Manually checking locations is slow and mistakes happen easily. It's hard to calculate distances or find shapes like areas or routes without special tools. This wastes time and can give wrong results.

The Solution

Geo-point and geo-shape types let you store locations and shapes directly in Elasticsearch. This means you can quickly search, filter, and analyze places by distance or area with simple commands.

Before vs After
Before
for location in locations:
    if distance(location, home) < 5:
        print(location)
After
{
  "mappings": {
    "properties": {
      "location": { "type": "geo_point" }
    }
  }
}

{
  "query": {
    "geo_distance": {
      "distance": "5mi",
      "location": "40,-70"
    }
  }
}
What It Enables

You can instantly find all points or shapes near a location or inside an area, making location-based searches fast and accurate.

Real Life Example

A delivery app uses geo-point to find all drivers within 3 miles of a customer, and geo-shape to check if a delivery address is inside a service zone.

Key Takeaways

Manual location checks are slow and error-prone.

Geo-point and geo-shape types store locations and shapes efficiently.

This enables fast, accurate geographic searches and filters.