0
0
Elasticsearchquery~30 mins

Geo-point and geo-shape types in Elasticsearch - Mini Project: Build & Apply

Choose your learning style9 modes available
Geo-point and Geo-shape Types in Elasticsearch
📖 Scenario: You are working on a location-based service that stores places and their areas on a map. You want to use Elasticsearch to store and search these locations efficiently.
🎯 Goal: Build an Elasticsearch index mapping that uses geo_point for storing exact locations and geo_shape for storing areas. Then, add sample documents and query them.
📋 What You'll Learn
Create an index mapping with location as geo_point
Add area field as geo_shape
Index sample documents with both fields
Query documents by location and shape
💡 Why This Matters
🌍 Real World
Location-based apps like delivery services, real estate, or mapping use geo_point and geo_shape to store and search places and areas.
💼 Career
Understanding geo data types in Elasticsearch is important for backend developers and data engineers working on geospatial search and analytics.
Progress0 / 4 steps
1
Create index mapping with geo_point and geo_shape
Create an Elasticsearch index called places with a mapping that has a location field of type geo_point and an area field of type geo_shape.
Elasticsearch
Need a hint?

Use the PUT method to create the index and define location as geo_point and area as geo_shape in the mappings.

2
Index sample documents with geo_point and geo_shape
Index a document into the places index with location set to latitude 40.7128 and longitude -74.0060, and area set to a polygon shape with coordinates [[[-74.0, 40.7], [-74.0, 40.8], [-73.9, 40.8], [-73.9, 40.7], [-74.0, 40.7]]].
Elasticsearch
Need a hint?

Use PUT /places/_doc/1 to add a document. Set location with lat and lon. Define area as a polygon with the given coordinates.

3
Query documents by geo_point location
Write a search query on the places index to find documents where the location is within 5km of latitude 40.7130 and longitude -74.0070 using a geo_distance query.
Elasticsearch
Need a hint?

Use a geo_distance query with distance set to "5km" and location coordinates as given.

4
Query documents by geo_shape area
Write a search query on the places index to find documents where the area intersects with a polygon shape defined by coordinates [[[-74.005, 40.705], [-74.005, 40.715], [-73.995, 40.715], [-73.995, 40.705], [-74.005, 40.705]]].
Elasticsearch
Need a hint?

Use a geo_shape query with relation set to "intersects" and the polygon coordinates given.