Bird
Raised Fist0
Elasticsearchquery~10 mins

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

Choose your learning style10 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.

Practice

(1/5)
1.

What is the main difference between geo_point and geo_shape types in Elasticsearch?

easy
A. geo_point stores a single location; geo_shape stores complex shapes like polygons.
B. geo_point stores polygons; geo_shape stores single points.
C. geo_point is used for text data; geo_shape is used for numbers.
D. geo_point stores multiple points; geo_shape stores only lines.

Solution

  1. Step 1: Understand geo_point type

    geo_point stores a single geographic location using latitude and longitude coordinates.
  2. Step 2: Understand geo_shape type

    geo_shape stores complex geographic shapes such as polygons, lines, or multi-points.
  3. Final Answer:

    geo_point stores a single location; geo_shape stores complex shapes like polygons. -> Option A
  4. Quick Check:

    Single point vs complex shape = C [OK]
Hint: Remember: point = one spot, shape = many spots connected [OK]
Common Mistakes:
  • Confusing points with polygons
  • Thinking geo_point stores multiple points
  • Mixing data types with geo types
2.

Which of the following is the correct way to define a geo_point field in an Elasticsearch mapping?

{
  "properties": {
    "location": {
      "type": "?"
    }
  }
}
easy
A. "geo_shape"
B. "geo_point"
C. "point_geo"
D. "location_point"

Solution

  1. Step 1: Recall Elasticsearch geo types

    Elasticsearch uses "geo_point" as the type name for single geographic points.
  2. Step 2: Match the correct type in mapping

    The mapping must specify "type": "geo_point" to store latitude and longitude.
  3. Final Answer:

    "geo_point" -> Option B
  4. Quick Check:

    Mapping type for point = "geo_point" [OK]
Hint: Use exact type names: geo_point for points [OK]
Common Mistakes:
  • Using incorrect type names like geo_shape for points
  • Typos in type string
  • Confusing field name with type
3.

Given this Elasticsearch document indexed with a geo_point field location:

{ "location": { "lat": 40.7128, "lon": -74.0060 } }

Which query will correctly find documents within 10km of this point?

medium
A. { "range": { "location": { "gte": "10km" } } }
B. { "geo_shape": { "location": { "shape": { "type": "point", "coordinates": [40.7128, -74.0060] }, "relation": "within" } } }
C. { "term": { "location": "40.7128,-74.0060" } }
D. { "geo_distance": { "distance": "10km", "location": { "lat": 40.7128, "lon": -74.0060 } } }

Solution

  1. Step 1: Identify correct query type for geo_point

    For geo_point, geo_distance query finds documents within a distance from a point.
  2. Step 2: Check query syntax and parameters

    { "geo_distance": { "distance": "10km", "location": { "lat": 40.7128, "lon": -74.0060 } } } uses geo_distance with correct distance and point coordinates.
  3. Final Answer:

    { "geo_distance": { "distance": "10km", "location": { "lat": 40.7128, "lon": -74.0060 } } } -> Option D
  4. Quick Check:

    geo_distance query = { "geo_distance": { "distance": "10km", "location": { "lat": 40.7128, "lon": -74.0060 } } } [OK]
Hint: Use geo_distance for points, geo_shape for polygons [OK]
Common Mistakes:
  • Using geo_shape query on geo_point field
  • Wrong coordinate order in geo_shape
  • Using term or range queries for geo data
4.

What is wrong with this Elasticsearch mapping for a geo_shape field named area?

{
  "properties": {
    "area": {
      "type": "geo_point"
    }
  }
}

The data to be stored is a polygon shape.

medium
A. The type should be geo_shape to store polygons.
B. The field name area is invalid for geo data.
C. The mapping must include coordinates property.
D. The type geo_point supports polygons by default.

Solution

  1. Step 1: Check field type for polygon data

    Polygons require geo_shape type, not geo_point.
  2. Step 2: Identify mapping error

    Mapping uses geo_point which only supports single points, so it cannot store polygons.
  3. Final Answer:

    The type should be geo_shape to store polygons. -> Option A
  4. Quick Check:

    Polygon needs geo_shape type = D [OK]
Hint: Polygons need geo_shape, not geo_point [OK]
Common Mistakes:
  • Using geo_point for polygon shapes
  • Assuming field name affects type
  • Adding coordinates in mapping instead of data
5.

You want to store a city boundary as a polygon and find all points inside it. Which Elasticsearch setup is correct?

{
  "mappings": {
    "properties": {
      "city_boundary": { "type": "?" },
      "user_location": { "type": "?" }
    }
  }
}

Choose the correct types for city_boundary and user_location.

hard
A. "geo_shape" for both city_boundary and user_location
B. "geo_point" for city_boundary and "geo_shape" for user_location
C. "geo_shape" for city_boundary and "geo_point" for user_location
D. "geo_point" for both city_boundary and user_location

Solution

  1. Step 1: Determine type for city boundary polygon

    City boundary is a polygon, so it requires geo_shape type.
  2. Step 2: Determine type for user location point

    User location is a single point, so it requires geo_point type.
  3. Step 3: Match types to fields

    Assign geo_shape to city_boundary and geo_point to user_location.
  4. Final Answer:

    "geo_shape" for city_boundary and "geo_point" for user_location -> Option C
  5. Quick Check:

    Polygon = geo_shape, Point = geo_point [OK]
Hint: Polygon needs geo_shape; point needs geo_point [OK]
Common Mistakes:
  • Swapping types between polygon and point
  • Using geo_point for polygons
  • Using geo_shape for single points unnecessarily
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard