The point data type in Elasticsearch is used for storing geographic coordinates as a single field. It represents a point in a two-dimensional space, typically used for latitude and longitude pairs. This data type is optimized for geospatial queries and aggregations, making it ideal for location-based searches and calculations.
While the geo_point data type is an alternative for storing geographic coordinates, the point data type is preferred when you need to work with non-geographic coordinate systems or when you want to store additional dimensions beyond latitude and longitude.
Example
PUT my-index
{
"mappings": {
"properties": {
"location": {
"type": "point"
}
}
}
}
PUT my-index/_doc/1
{
"location": [40.7128, -74.0060]
}
Common issues or misuses
- Confusing point with geo_point: Remember that point is for general 2D coordinates, while geo_point is specifically for geographic coordinates.
- Incorrect coordinate order: Ensure you consistently use the same order (e.g.,
[y, x]
or[latitude, longitude]
) when indexing and querying. - Not considering precision: The point data type uses double-precision floating-point numbers, which may lead to small inaccuracies in certain calculations.
- Overlooking the need for a geo_shape field: If you need to represent complex geometries, consider using geo_shape instead of point.
Frequently Asked Questions
Q: What's the difference between point and geo_point in Elasticsearch?
A: The point data type is for general 2D coordinates, while geo_point is specifically optimized for geographic (latitude and longitude) coordinates. Use point for non-geographic coordinate systems or when you need additional dimensions.
Q: Can I use the point data type for 3D coordinates?
A: No, the point data type in Elasticsearch is limited to two dimensions. For 3D coordinates, you might need to use separate fields or consider alternative data structures.
Q: How do I perform distance calculations with point fields?
A: You can use the distance function in Elasticsearch queries to calculate distances between points. For example: "script": "distance(params.lat, params.lon, doc['location'])"
Q: Is the point data type suitable for high-precision coordinate storage?
A: The point data type uses double-precision floating-point numbers, which provide good precision for most use cases. However, for extremely high-precision applications, you may need to consider alternative storage methods.
Q: Can I index multiple points in a single field?
A: No, a single point field can only store one set of coordinates. If you need to store multiple points, consider using an array of point fields or the geo_shape data type for more complex geometries.