0
0
Elasticsearchquery~10 mins

Geo-point and geo-shape types in Elasticsearch - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Geo-point and geo-shape types
Define Mapping
Add geo-point or geo-shape field
Index Document with geo data
Elasticsearch stores geo data
Run geo queries (distance, shape)
Get matching documents
This flow shows how you define geo fields, index geo data, and query it in Elasticsearch.
Execution Sample
Elasticsearch
PUT /places
{
  "mappings": {
    "properties": {
      "location": { "type": "geo_point" }
    }
  }
}

POST /places/_doc
{
  "name": "Park",
  "location": "40.7128,-74.0060"
}
Defines an index with a geo_point field and indexes a document with latitude and longitude.
Execution Table
StepActionInput/ConditionResult/Output
1Define index mappinglocation field type geo_pointMapping created with geo_point field
2Index documentlocation: "40.7128,-74.0060"Document stored with geo_point coordinates
3Query documentsgeo_distance query within 5km of 40.713,-74.007Documents matching location within radius returned
4Define geo_shape fieldarea field type geo_shapeMapping updated with geo_shape field
5Index documentarea: polygon coordinatesDocument stored with geo_shape geometry
6Query documentsgeo_shape query intersects polygonDocuments with intersecting shapes returned
7EndNo more actionsExecution stops
💡 All geo-point and geo-shape operations completed
Variable Tracker
VariableStartAfter Step 2After Step 5Final
mappingempty{"location": {"type": "geo_point"}}{"location": {"type": "geo_point"}, "area": {"type": "geo_shape"}}{"location": {"type": "geo_point"}, "area": {"type": "geo_shape"}}
documentnone{"name": "Park", "location": "40.7128,-74.0060"}{"name": "Park", "location": "40.7128,-74.0060", "area": "polygon"}{"name": "Park", "location": "40.7128,-74.0060", "area": "polygon"}
query_resultnonedocuments within 5kmdocuments within 5kmdocuments intersecting polygon
Key Moments - 3 Insights
Why do we specify "geo_point" or "geo_shape" in the mapping?
Because Elasticsearch needs to know the type of geo data to index and query it correctly, as shown in execution_table step 1 and 4.
How is a geo_point value formatted when indexing a document?
It can be a string with "lat,lon" like "40.7128,-74.0060" as in step 2, or an object with lat and lon keys.
What is the difference between geo_point and geo_shape queries?
geo_point queries use distance or bounding box filters (step 3), while geo_shape queries check spatial relationships like intersects (step 6).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what type is the 'location' field after step 1?
Ageo_point
Bgeo_shape
Ctext
Dkeyword
💡 Hint
Check the 'Result/Output' column in step 1 of execution_table
At which step does the mapping get updated to include a geo_shape field?
AStep 2
BStep 5
CStep 4
DStep 6
💡 Hint
Look for 'Define geo_shape field' action in execution_table
If the document's location was changed to an object {"lat": 40.7128, "lon": -74.0060}, how would step 2's input change?
Alocation: "40.7128,-74.0060"
Blocation: {"lat": 40.7128, "lon": -74.0060}
Clocation: "-74.0060,40.7128"
Dlocation: "40.7128"
💡 Hint
Refer to key_moments about geo_point value formats
Concept Snapshot
Geo-point and geo-shape types in Elasticsearch:
- Define geo_point or geo_shape in index mapping
- geo_point stores latitude and longitude
- geo_shape stores complex shapes like polygons
- Index documents with geo data accordingly
- Query using geo_distance for points or geo_shape queries for shapes
- Enables spatial search and filtering
Full Transcript
This visual execution shows how Elasticsearch handles geo-point and geo-shape types. First, you define the mapping with a geo_point or geo_shape field. Then you index documents with location data as coordinates or shapes. Elasticsearch stores this data in a special way to allow spatial queries. You can query documents by distance from a point or by spatial relationships with shapes. The execution table traces each step from defining mapping, indexing documents, to querying. The variable tracker shows how mapping and documents change. Key moments clarify common confusions like why mapping types matter and how geo_point values are formatted. The quiz tests understanding of mapping types, steps, and data formats. This helps beginners see exactly how geo data flows through Elasticsearch indexing and querying.