ST_DISTANCE for calculating a distance, also usable for sorting
These features can be implemented in ES|QL, but we believe we do not need to implement both functions, as we can perform Lucene-pushdown optimization identically in both cases, so we'll implement the more generic function only: double ST_DISTANCE(geomA, geomB).
This can be used for calculating a distance, filter and sorting based on the context in the query:
Distance calculations
FROM airports
| EVAL distance = ST_DISTANCE(location, city_location)
Filtering results
FROM airports
| WHERE ST_DISTANCE(location, TO_GEOPOINT("POINT(12 55)")) < 500000
### Tasks
- [x] Review existing Elasticsearch support for distance filtering and sorting
- [x] Review PostGIS and OGC specifications for these functions
- [x] Implement raw ST_DISTANCE function
- [x] Support distance filtering
- [x] Support distance calculations
- [x] Support distance sorting
- [ ] https://github.com/elastic/elasticsearch/issues/109972
- [ ] https://github.com/elastic/elasticsearch/issues/109973
- [x] Documentation
Description
The Elasticsearch
_search
API supports distance filtering and sorting:In PostGIS there are two related functions:
ST_DWITHIN
for filtering by distanceST_DISTANCE
for calculating a distance, also usable for sortingThese features can be implemented in ES|QL, but we believe we do not need to implement both functions, as we can perform Lucene-pushdown optimization identically in both cases, so we'll implement the more generic function only:
double ST_DISTANCE(geomA, geomB)
.This can be used for calculating a distance, filter and sorting based on the context in the query:
Distance calculations
Filtering results
Sorting results