ES|QL ST_GEOHEX function
geometry- Expression of type
geo_point. Ifnull, the function returnsnull. precision- Expression of type
integer. Ifnull, the function returnsnull. Valid values are between 0 and 15. bounds-
Optional bounds to filter the grid tiles, a
geo_shapeof typeBBOX. UseST_ENVELOPEif thegeo_shapeis of any other type.
Calculates the geohex, the H3 cell-id, of the supplied geo_point at the specified precision. The result is long encoded. Use TO_STRING to convert the result to a string, TO_LONG to convert it to a long, or TO_GEOSHAPE to calculate the geo_shape bounding geometry. These functions are related to the geo_grid query and the geohex_grid aggregation.
| geometry | precision | bounds | result |
|---|---|---|---|
| geo_point | integer | geo_shape | geohex |
| geo_point | integer | geohex |
FROM airports
| EVAL geohex = ST_GEOHEX(location, 1)
| STATS
count = COUNT(geohex),
centroid = ST_CENTROID_AGG(location)
BY geohex
| WHERE count >= 10
| EVAL geohexString = TO_STRING(geohex)
| KEEP count, centroid, geohexString
| SORT count DESC, geohexString ASC
| count:long | centroid:geo_point | geohexString:keyword |
|---|---|---|
| 22 | POINT (7.250850197689777 48.21363834643059) | 811fbffffffffff |
| 18 | POINT (-80.64959161449224 40.04119813675061) | 812abffffffffff |
| 17 | POINT (-0.7606179875266903 52.86413913565304) | 81197ffffffffff |
| 13 | POINT (22.53157936179867 41.98255742864254) | 811efffffffffff |
| 13 | POINT (78.30096947387435 26.073904778951636) | 813dbffffffffff |
| 12 | POINT (-76.39781514415517 45.16300531569868) | 812bbffffffffff |
| 12 | POINT (-100.30120467301458 20.114154297625646) | 8149bffffffffff |
| 11 | POINT (18.037187419831753 48.66540593306788) | 811e3ffffffffff |
| 11 | POINT (-83.42379064553164 33.18388901439241) | 8144fffffffffff |
| 11 | POINT (-99.4237939513881 27.100012352774765) | 8148bffffffffff |
| 10 | POINT (128.01009018346667 35.8699960866943) | 8130fffffffffff |