ES|QL spatial functions
Serverless Stack
ES|QL supports these spatial functions:
ST_DISTANCEST_INTERSECTSST_DISJOINTST_CONTAINSST_WITHINST_XST_YST_ENVELOPEStack ServerlessST_GEOTILEStack ServerlessST_GEOHEXStack ServerlessST_GEOHASHStack Serverless
Syntax
Parameters
geomA- Expression of type
geo_pointorcartesian_point. Ifnull, the function returnsnull. geomB-
Expression of type
geo_pointorcartesian_point. Ifnull, the function returnsnull. The second parameter must also have the same coordinate system as the first. This means it is not possible to combinegeo_pointandcartesian_pointparameters.
Description
Computes the distance between two points. For cartesian geometries, this is the pythagorean distance in the same units as the original coordinates. For geographic geometries, this is the circular distance along the great circle in meters.
Supported types
| geomA | geomB | result |
|---|---|---|
| cartesian_point | cartesian_point | double |
| geo_point | geo_point | double |
Example
FROM airports
| WHERE abbrev == "CPH"
| EVAL distance = ST_DISTANCE(location, city_location)
| KEEP abbrev, name, location, city_location, distance
| abbrev:k | name:text | location:geo_point | city_location:geo_point | distance:d |
|---|---|---|---|---|
| CPH | Copenhagen | POINT(12.6493508684508 55.6285017221528) | POINT(12.5683 55.6761) | 7339.573896618216 |
Syntax
Parameters
geomA- Expression that is either a geometry (
geo_point,cartesian_point,geo_shapeorcartesian_shape) or a geo-grid value (geohash,geotile,geohex). Ifnull, the function returnsnull. geomB-
Expression that is either a geometry (
geo_point,cartesian_point,geo_shapeorcartesian_shape) or a geo-grid value (geohash,geotile,geohex). Ifnull, the function returnsnull. The second parameter must also have the same coordinate system as the first. This means it is not possible to combinegeo_*andcartesian_*parameters.
Description
Returns true if two geometries intersect. They intersect if they have any point in common, including their interior points (points along lines or within polygons). This is the inverse of the ST_DISJOINT function. In mathematical terms: ST_Intersects(A, B) ⇔ A ⋂ B ≠ ∅
Supported types
| geomA | geomB | result |
|---|---|---|
| cartesian_point | cartesian_point | boolean |
| cartesian_point | cartesian_shape | boolean |
| cartesian_shape | cartesian_point | boolean |
| cartesian_shape | cartesian_shape | boolean |
| geo_point | geo_point | boolean |
| geo_point | geo_shape | boolean |
| geo_point | geohash | boolean |
| geo_point | geohex | boolean |
| geo_point | geotile | boolean |
| geo_shape | geo_point | boolean |
| geo_shape | geo_shape | boolean |
| geohash | geo_point | boolean |
| geohex | geo_point | boolean |
| geotile | geo_point | boolean |
Example
FROM airports
| WHERE ST_INTERSECTS(location, TO_GEOSHAPE("POLYGON((42 14, 43 14, 43 15, 42 15, 42 14))"))
| abbrev:keyword | city:keyword | city_location:geo_point | country:keyword | location:geo_point | name:text | scalerank:i | type:k |
|---|---|---|---|---|---|---|---|
| HOD | Al Ḩudaydah | POINT(42.9511 14.8022) | Yemen | POINT(42.97109630194 14.7552534413725) | Hodeidah Int'l | 9 | mid |
Syntax
Parameters
geomA- Expression that is either a geometry (
geo_point,cartesian_point,geo_shapeorcartesian_shape) or a geo-grid value (geohash,geotile,geohex). Ifnull, the function returnsnull. geomB-
Expression that is either a geometry (
geo_point,cartesian_point,geo_shapeorcartesian_shape) or a geo-grid value (geohash,geotile,geohex). Ifnull, the function returnsnull. The second parameter must also have the same coordinate system as the first. This means it is not possible to combinegeo_*andcartesian_*parameters.
Description
Returns whether the two geometries or geometry columns are disjoint. This is the inverse of the ST_INTERSECTS function. In mathematical terms: ST_Disjoint(A, B) ⇔ A ⋂ B = ∅
Supported types
| geomA | geomB | result |
|---|---|---|
| cartesian_point | cartesian_point | boolean |
| cartesian_point | cartesian_shape | boolean |
| cartesian_shape | cartesian_point | boolean |
| cartesian_shape | cartesian_shape | boolean |
| geo_point | geo_point | boolean |
| geo_point | geo_shape | boolean |
| geo_point | geohash | boolean |
| geo_point | geohex | boolean |
| geo_point | geotile | boolean |
| geo_shape | geo_point | boolean |
| geo_shape | geo_shape | boolean |
| geohash | geo_point | boolean |
| geohex | geo_point | boolean |
| geotile | geo_point | boolean |
Example
FROM airport_city_boundaries
| WHERE ST_DISJOINT(city_boundary, TO_GEOSHAPE("POLYGON((-10 -60, 120 -60, 120 60, -10 60, -10 -60))"))
| KEEP abbrev, airport, region, city, city_location
| abbrev:keyword | airport:text | region:text | city:keyword | city_location:geo_point |
|---|---|---|---|---|
| ACA | General Juan N Alvarez Int'l | Acapulco de Juárez | Acapulco de Juárez | POINT (-99.8825 16.8636) |
Syntax
Parameters
geomA- Expression of type
geo_point,cartesian_point,geo_shapeorcartesian_shape. Ifnull, the function returnsnull. geomB-
Expression of type
geo_point,cartesian_point,geo_shapeorcartesian_shape. Ifnull, the function returnsnull. The second parameter must also have the same coordinate system as the first. This means it is not possible to combinegeo_*andcartesian_*parameters.
Description
Returns whether the first geometry contains the second geometry. This is the inverse of the ST_WITHIN function.
Supported types
| geomA | geomB | result |
|---|---|---|
| cartesian_point | cartesian_point | boolean |
| cartesian_point | cartesian_shape | boolean |
| cartesian_shape | cartesian_point | boolean |
| cartesian_shape | cartesian_shape | boolean |
| geo_point | geo_point | boolean |
| geo_point | geo_shape | boolean |
| geo_shape | geo_point | boolean |
| geo_shape | geo_shape | boolean |
Example
FROM airport_city_boundaries
| WHERE ST_CONTAINS(city_boundary, TO_GEOSHAPE("POLYGON((109.35 18.3, 109.45 18.3, 109.45 18.4, 109.35 18.4, 109.35 18.3))"))
| KEEP abbrev, airport, region, city, city_location
| abbrev:keyword | airport:text | region:text | city:keyword | city_location:geo_point |
|---|---|---|---|---|
| SYX | Sanya Phoenix Int'l | 天涯区 | Sanya | POINT(109.5036 18.2533) |
Syntax
Parameters
geomA- Expression of type
geo_point,cartesian_point,geo_shapeorcartesian_shape. Ifnull, the function returnsnull. geomB-
Expression of type
geo_point,cartesian_point,geo_shapeorcartesian_shape. Ifnull, the function returnsnull. The second parameter must also have the same coordinate system as the first. This means it is not possible to combinegeo_*andcartesian_*parameters.
Description
Returns whether the first geometry is within the second geometry. This is the inverse of the ST_CONTAINS function.
Supported types
| geomA | geomB | result |
|---|---|---|
| cartesian_point | cartesian_point | boolean |
| cartesian_point | cartesian_shape | boolean |
| cartesian_shape | cartesian_point | boolean |
| cartesian_shape | cartesian_shape | boolean |
| geo_point | geo_point | boolean |
| geo_point | geo_shape | boolean |
| geo_shape | geo_point | boolean |
| geo_shape | geo_shape | boolean |
Example
FROM airport_city_boundaries
| WHERE ST_WITHIN(city_boundary, TO_GEOSHAPE("POLYGON((109.1 18.15, 109.6 18.15, 109.6 18.65, 109.1 18.65, 109.1 18.15))"))
| KEEP abbrev, airport, region, city, city_location
| abbrev:keyword | airport:text | region:text | city:keyword | city_location:geo_point |
|---|---|---|---|---|
| SYX | Sanya Phoenix Int'l | 天涯区 | Sanya | POINT(109.5036 18.2533) |
Syntax
Parameters
point-
Expression of type
geo_pointorcartesian_point. Ifnull, the function returnsnull.
Description
Extracts the x coordinate from the supplied point. If the points is of type geo_point this is equivalent to extracting the longitude value.
Supported types
| point | result |
|---|---|
| cartesian_point | double |
| geo_point | double |
Example
ROW point = TO_GEOPOINT("POINT(42.97109629958868 14.7552534006536)")
| EVAL x = ST_X(point), y = ST_Y(point)
| point:geo_point | x:double | y:double |
|---|---|---|
| POINT(42.97109629958868 14.7552534006536) | 42.97109629958868 | 14.7552534006536 |
Syntax
Parameters
point-
Expression of type
geo_pointorcartesian_point. Ifnull, the function returnsnull.
Description
Extracts the y coordinate from the supplied point. If the points is of type geo_point this is equivalent to extracting the latitude value.
Supported types
| point | result |
|---|---|
| cartesian_point | double |
| geo_point | double |
Example
ROW point = TO_GEOPOINT("POINT(42.97109629958868 14.7552534006536)")
| EVAL x = ST_X(point), y = ST_Y(point)
| point:geo_point | x:double | y:double |
|---|---|---|
| POINT(42.97109629958868 14.7552534006536) | 42.97109629958868 | 14.7552534006536 |
Serverless Stack
Syntax
Parameters
geometry-
Expression of type
geo_point,geo_shape,cartesian_pointorcartesian_shape. Ifnull, the function returnsnull.
Description
Determines the minimum bounding box of the supplied geometry.
Supported types
| geometry | result |
|---|---|
| cartesian_point | cartesian_shape |
| cartesian_shape | cartesian_shape |
| geo_point | geo_shape |
| geo_shape | geo_shape |
Example
FROM airport_city_boundaries
| WHERE abbrev == "CPH"
| EVAL envelope = ST_ENVELOPE(city_boundary)
| KEEP abbrev, airport, envelope
| abbrev:keyword | airport:text | envelope:geo_shape |
|---|---|---|
| CPH | Copenhagen | BBOX(12.453, 12.6398, 55.7327, 55.6318) |
Serverless Stack
Syntax
Parameters
point-
Expression of type
geo_point,geo_shape,cartesian_pointorcartesian_shape. Ifnull, the function returnsnull.
Description
Extracts the maximum value of the x coordinates from the supplied geometry. If the geometry is of type geo_point or geo_shape this is equivalent to extracting the maximum longitude value.
Supported types
| point | result |
|---|---|
| cartesian_point | double |
| cartesian_shape | double |
| geo_point | double |
| geo_shape | double |
Example
FROM airport_city_boundaries
| WHERE abbrev == "CPH"
| EVAL envelope = ST_ENVELOPE(city_boundary)
| EVAL xmin = ST_XMIN(envelope), xmax = ST_XMAX(envelope), ymin = ST_YMIN(envelope), ymax = ST_YMAX(envelope)
| KEEP abbrev, airport, xmin, xmax, ymin, ymax
| abbrev:keyword | airport:text | xmin:double | xmax:double | ymin:double | ymax:double |
|---|---|---|---|---|---|
| CPH | Copenhagen | 12.453 | 12.6398 | 55.6318 | 55.7327 |
Serverless Stack
Syntax
Parameters
point-
Expression of type
geo_point,geo_shape,cartesian_pointorcartesian_shape. Ifnull, the function returnsnull.
Description
Extracts the minimum value of the x coordinates from the supplied geometry. If the geometry is of type geo_point or geo_shape this is equivalent to extracting the minimum longitude value.
Supported types
| point | result |
|---|---|
| cartesian_point | double |
| cartesian_shape | double |
| geo_point | double |
| geo_shape | double |
Example
FROM airport_city_boundaries
| WHERE abbrev == "CPH"
| EVAL envelope = ST_ENVELOPE(city_boundary)
| EVAL xmin = ST_XMIN(envelope), xmax = ST_XMAX(envelope), ymin = ST_YMIN(envelope), ymax = ST_YMAX(envelope)
| KEEP abbrev, airport, xmin, xmax, ymin, ymax
| abbrev:keyword | airport:text | xmin:double | xmax:double | ymin:double | ymax:double |
|---|---|---|---|---|---|
| CPH | Copenhagen | 12.453 | 12.6398 | 55.6318 | 55.7327 |
Serverless Stack
Syntax
Parameters
point-
Expression of type
geo_point,geo_shape,cartesian_pointorcartesian_shape. Ifnull, the function returnsnull.
Description
Extracts the maximum value of the y coordinates from the supplied geometry. If the geometry is of type geo_point or geo_shape this is equivalent to extracting the maximum latitude value.
Supported types
| point | result |
|---|---|
| cartesian_point | double |
| cartesian_shape | double |
| geo_point | double |
| geo_shape | double |
Example
FROM airport_city_boundaries
| WHERE abbrev == "CPH"
| EVAL envelope = ST_ENVELOPE(city_boundary)
| EVAL xmin = ST_XMIN(envelope), xmax = ST_XMAX(envelope), ymin = ST_YMIN(envelope), ymax = ST_YMAX(envelope)
| KEEP abbrev, airport, xmin, xmax, ymin, ymax
| abbrev:keyword | airport:text | xmin:double | xmax:double | ymin:double | ymax:double |
|---|---|---|---|---|---|
| CPH | Copenhagen | 12.453 | 12.6398 | 55.6318 | 55.7327 |
Serverless Stack
Syntax
Parameters
point-
Expression of type
geo_point,geo_shape,cartesian_pointorcartesian_shape. Ifnull, the function returnsnull.
Description
Extracts the minimum value of the y coordinates from the supplied geometry. If the geometry is of type geo_point or geo_shape this is equivalent to extracting the minimum latitude value.
Supported types
| point | result |
|---|---|
| cartesian_point | double |
| cartesian_shape | double |
| geo_point | double |
| geo_shape | double |
Example
FROM airport_city_boundaries
| WHERE abbrev == "CPH"
| EVAL envelope = ST_ENVELOPE(city_boundary)
| EVAL xmin = ST_XMIN(envelope), xmax = ST_XMAX(envelope), ymin = ST_YMIN(envelope), ymax = ST_YMAX(envelope)
| KEEP abbrev, airport, xmin, xmax, ymin, ymax
| abbrev:keyword | airport:text | xmin:double | xmax:double | ymin:double | ymax:double |
|---|---|---|---|---|---|
| CPH | Copenhagen | 12.453 | 12.6398 | 55.6318 | 55.7327 |
Serverless Stack
Syntax
Parameters
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 29. bounds-
Optional bounds to filter the grid tiles, a
geo_shapeof typeBBOX. UseST_ENVELOPEif thegeo_shapeis of any other type.
Description
Calculates the geotile 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 geotile_grid aggregation.
Supported types
| geometry | precision | bounds | result |
|---|---|---|---|
| geo_point | integer | geo_shape | geotile |
| geo_point | integer | geotile |
Example
FROM airports
| EVAL geotile = ST_GEOTILE(location, 2)
| STATS
count = COUNT(geotile),
centroid = ST_CENTROID_AGG(location)
BY geotile
| EVAL geotileString = TO_STRING(geotile)
| SORT count DESC, geotileString ASC
| KEEP count, centroid, geotileString
| count:long | centroid:geo_point | geotileString:keyword |
|---|---|---|
| 286 | POINT (39.31202001609169 35.149993664386415) | 2/2/1 |
| 197 | POINT (-55.387361375756825 31.952955322292855) | 2/1/1 |
| 136 | POINT (-110.97162496141048 36.87185255084734) | 2/0/1 |
| 106 | POINT (119.35907618669827 25.46263281488791) | 2/3/1 |
| 67 | POINT (-58.031108492373754 -22.624166105151065) | 2/1/2 |
| 46 | POINT (142.95455511274707 -20.581492295427978) | 2/3/2 |
| 34 | POINT (31.38476753634784 -14.64374022804858) | 2/2/2 |
| 8 | POINT (-160.0723083713092 -19.124013530672528) | 2/0/2 |
| 6 | POINT (23.95813101902604 70.17537698848173) | 2/2/0 |
| 3 | POINT (-133.4001641627401 72.06833167467266) | 2/0/0 |
| 2 | POINT (-68.47209956031293 66.77569948369637) | 2/1/0 |
Serverless Stack
Syntax
Parameters
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.
Description
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.
Supported types
| geometry | precision | bounds | result |
|---|---|---|---|
| geo_point | integer | geo_shape | geohex |
| geo_point | integer | geohex |
Example
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 |
Serverless Stack
Syntax
Parameters
geometry- Expression of type
geo_point. Ifnull, the function returnsnull. precision- Expression of type
integer. Ifnull, the function returnsnull. Valid values are between 1 and 12. bounds-
Optional bounds to filter the grid tiles, a
geo_shapeof typeBBOX. UseST_ENVELOPEif thegeo_shapeis of any other type.
Description
Calculates the geohash 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 geohash_grid aggregation.
Supported types
| geometry | precision | bounds | result |
|---|---|---|---|
| geo_point | integer | geo_shape | geohash |
| geo_point | integer | geohash |
Example
FROM airports
| EVAL geohash = ST_GEOHASH(location, 1)
| STATS
count = COUNT(geohash),
centroid = ST_CENTROID_AGG(location)
BY geohash
| WHERE count >= 10
| EVAL geohashString = TO_STRING(geohash)
| KEEP count, centroid, geohashString
| SORT count DESC, geohashString ASC
| count:long | centroid:geo_point | geohashString:keyword |
|---|---|---|
| 118 | POINT (-77.41857436454018 26.96522968734409) | d |
| 96 | POINT (23.181679135886952 27.295384635654045) | s |
| 94 | POINT (70.94076107503807 25.691916451026547) | t |
| 90 | POINT (-104.3941700803116 30.811849871650338) | 9 |
| 89 | POINT (18.71573683606942 53.165169130707305) | u |
| 85 | POINT (114.3722876966657 24.908398092505248) | w |
| 51 | POINT (-61.44522591713159 -22.87209844956284) | 6 |
| 38 | POINT (-9.429514887252529 25.497624435045413) | e |
| 34 | POINT (-111.8071846965262 52.464381378993174) | c |
| 30 | POINT (28.7045472683385 -14.706001980230212) | k |
| 28 | POINT (159.52750137208827 -25.555616633001982) | r |
| 22 | POINT (-4.410395708612421 54.90304926367985) | g |
| 21 | POINT (-69.40534970590046 50.93379438189523) | f |
| 17 | POINT (114.05526293222519 -10.898114638950895) | q |
| 16 | POINT (147.40052131412085 21.054660080408212) | x |
| 13 | POINT (63.64716878519035 54.37333276101317) | v |
| 12 | POINT (-39.53510569408536 -11.72166372067295) | 7 |