Skip to content

Commit 473406d

Browse files
Support geohash, geotile and geohex grid types in ST_INTERSECTS (#133546)
In the work at #129581 we added new geo-grid types: `GEOHASH`, `GEOTILE` and `GEOHEX`, as well as support functions for creating these from `geo_point`, `long` and `keyword`. However, one of the key use cases we wish to replicate from the Query DSL is the grid search, and this involves the need to include the grid id inside a search predicate, in particular the `ST_INTERSECTS` function. For example: ``` FROM airports | WHERE ST_INTERSECTS(location, TO_GEOTILE("3/4/3")) | STATS count = COUNT(*), centroid = ST_CENTROID_AGG(location) ``` Since ST_INTERSECTS and ST_DISJOINT are converse of each other, we also added this support to that function.
1 parent b81985e commit 473406d

30 files changed

+1057
-108
lines changed

docs/changelog/133546.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 133546
2+
summary: "Support geohash, geotile and geohex grid types in ST_INTERSECTS and ST_DISJOINT"
3+
area: "ES|QL"
4+
type: enhancement
5+
issues: []

docs/reference/query-languages/esql/_snippets/functions/parameters/st_disjoint.md

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/parameters/st_intersects.md

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/types/st_disjoint.md

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/types/st_intersects.md

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/kibana/definition/functions/st_disjoint.json

Lines changed: 124 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/kibana/definition/functions/st_intersects.json

Lines changed: 124 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClusterSpecIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ protected void shouldSkipTest(String testName) throws IOException {
147147
hasCapabilities(adminClient(), List.of(ENABLE_LOOKUP_JOIN_ON_REMOTE.capabilityName()))
148148
);
149149
}
150-
// Unmapped fields require a coorect capability response from every cluster, which isn't currently implemented.
150+
// Unmapped fields require a correct capability response from every cluster, which isn't currently implemented.
151151
assumeFalse("UNMAPPED FIELDS not yet supported in CCS", testCase.requiredCapabilities.contains(UNMAPPED_FIELDS.capabilityName()));
152152
// Tests that use capabilities not supported in CCS
153153
assumeFalse(

x-pack/plugin/esql/qa/testFixtures/src/main/resources/spatial-grid.csv-spec

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,62 @@ count:long | centroid:geo_point | geohashString:keywo
320320
2 | POINT (16.706149326637387 32.37822346854955) | sm | POLYGON((11.25 28.125, 22.5 28.125, 22.5 33.75, 11.25 33.75, 11.25 28.125))
321321
;
322322

323+
gridGeohashDocsFromCell
324+
required_capability: spatial_grid_intersects
325+
326+
FROM airports
327+
| WHERE ST_INTERSECTS(location, TO_GEOHASH("u1"))
328+
| STATS
329+
count = COUNT(*),
330+
centroid = ST_CENTROID_AGG(location)
331+
;
332+
333+
count:long | centroid:geo_point
334+
8 | POINT (6.351574736181647 51.8981519783847)
335+
;
336+
337+
gridIntersectsDisjointGeohash
338+
required_capability: spatial_grid_intersects
339+
340+
FROM airports
341+
| EVAL intersects = ST_INTERSECTS(location, "u1"::geohash)
342+
| EVAL disjoint = ST_DISJOINT(location, "u1"::geohash)
343+
| STATS count = COUNT(*) BY intersects, disjoint
344+
| SORT count ASC
345+
;
346+
347+
count:long | intersects:boolean | disjoint:boolean
348+
8 | true | false
349+
883 | false | true
350+
;
351+
352+
gridGeohashLiteralFromCell
353+
required_capability: spatial_grid_intersects
354+
355+
ROW location = ["POINT (6.360728044651057 47.94084087577894)", "POINT (6.351574736181647 51.8981519783847)", "POINT (5.268637698941997 42.747250193330856)"]
356+
| EVAL location = TO_GEOPOINT(location)
357+
| MV_EXPAND location
358+
| WHERE ST_INTERSECTS(location, "u1"::geohash)
359+
;
360+
361+
location:geo_point
362+
POINT (6.351574736181647 51.8981519783847)
363+
;
364+
365+
gridGeohashLiteralFromCellDisjoint
366+
required_capability: spatial_grid_intersects
367+
368+
ROW location = ["POINT (6.360728044651057 47.94084087577894)", "POINT (6.351574736181647 51.8981519783847)", "POINT (5.268637698941997 42.747250193330856)"]
369+
| EVAL location = location::geo_point
370+
| MV_EXPAND location
371+
| WHERE ST_DISJOINT(location, "u1"::geohash)
372+
;
373+
374+
location:geo_point
375+
POINT (6.360728044651057 47.94084087577894)
376+
POINT (5.268637698941997 42.747250193330856)
377+
;
378+
323379
gridGeohashStatsByWhereUK
324380
required_capability: spatial_grid_types
325381

@@ -688,6 +744,62 @@ count:long | centroid:geo_point | geotileString:keywor
688744
79 | POINT (24.516750878736943 23.93036561181085) | 3/4/3 | POLYGON((0.0 0.0, 45.0 0.0, 45.0 40.979898069620134, 0.0 40.979898069620134, 0.0 0.0))
689745
;
690746

747+
gridGeotileDocsFromCell
748+
required_capability: spatial_grid_intersects
749+
750+
FROM airports
751+
| WHERE ST_INTERSECTS(location, TO_GEOTILE("3/4/3"))
752+
| STATS
753+
count = COUNT(*),
754+
centroid = ST_CENTROID_AGG(location)
755+
;
756+
757+
count:long | centroid:geo_point
758+
79 | POINT (24.516750878736943 23.93036561181085)
759+
;
760+
761+
gridIntersectsDisjointGeotile
762+
required_capability: spatial_grid_intersects
763+
764+
FROM airports
765+
| EVAL intersects = ST_INTERSECTS(location, "3/4/3"::geotile)
766+
| EVAL disjoint = ST_DISJOINT(location, "3/4/3"::geotile)
767+
| STATS count = COUNT(*) BY intersects, disjoint
768+
| SORT count ASC
769+
;
770+
771+
count:long | intersects:boolean | disjoint:boolean
772+
79 | true | false
773+
812 | false | true
774+
;
775+
776+
gridGeotileLiteralFromCell
777+
required_capability: spatial_grid_intersects
778+
779+
ROW location = ["POINT (6.360728044651057 47.94084087577894)", "POINT (24.516750878736943 23.93036561181085)", "POINT (5.268637698941997 42.747250193330856)"]
780+
| EVAL location = TO_GEOPOINT(location)
781+
| MV_EXPAND location
782+
| WHERE ST_INTERSECTS(location, "3/4/3"::geotile)
783+
;
784+
785+
location:geo_point
786+
POINT (24.516750878736943 23.93036561181085)
787+
;
788+
789+
gridGeotileLiteralFromCellDisjoint
790+
required_capability: spatial_grid_intersects
791+
792+
ROW location = ["POINT (6.360728044651057 47.94084087577894)", "POINT (24.516750878736943 23.93036561181085)", "POINT (5.268637698941997 42.747250193330856)"]
793+
| EVAL location = location::geo_point
794+
| MV_EXPAND location
795+
| WHERE ST_DISJOINT(location, "3/4/3"::geotile)
796+
;
797+
798+
location:geo_point
799+
POINT (6.360728044651057 47.94084087577894)
800+
POINT (5.268637698941997 42.747250193330856)
801+
;
802+
691803
gridGeotileStatsByWhereUK
692804
required_capability: spatial_grid_types
693805

@@ -1123,6 +1235,62 @@ POINT (13.1442589810713 32.6691695504993) | 813fbffffffffff | 813fbffffffffff
11231235
POINT (118.12696884672 24.537192570557) | 8141bffffffffff | null | POLYGON ((121.34751445935747 26.200276060455465, 120.50339385995798 29.892985338693542, 116.26130043917948 31.68090796798786, 112.74092235558841 29.367231998154967, 113.70376749169584 25.199133186716526, 117.99047716641066 23.5089519597363, 119.64146543031175 24.728661050965922, 121.34751445935747 26.200276060455465))
11241236
;
11251237

1238+
gridGeohexDocsFromCell
1239+
required_capability: spatial_grid_intersects
1240+
1241+
FROM airports
1242+
| WHERE ST_INTERSECTS(location, TO_GEOHEX("81397ffffffffff"))
1243+
| STATS
1244+
count = COUNT(*),
1245+
centroid = ST_CENTROID_AGG(location)
1246+
;
1247+
1248+
count:long | centroid:geo_point
1249+
7 | POINT (2.475211258445467 41.32352174592337)
1250+
;
1251+
1252+
gridIntersectsDisjointGeohex
1253+
required_capability: spatial_grid_intersects
1254+
1255+
FROM airports
1256+
| EVAL intersects = ST_INTERSECTS(location, "81397ffffffffff"::geohex)
1257+
| EVAL disjoint = ST_DISJOINT(location, "81397ffffffffff"::geohex)
1258+
| STATS count = COUNT(*) BY intersects, disjoint
1259+
| SORT count ASC
1260+
;
1261+
1262+
count:long | intersects:boolean | disjoint:boolean
1263+
7 | true | false
1264+
884 | false | true
1265+
;
1266+
1267+
gridGeohexLiteralFromCell
1268+
required_capability: spatial_grid_intersects
1269+
1270+
ROW location = ["POINT (6.360728044651057 47.94084087577894)", "POINT (2.475211258445467 41.32352174592337)", "POINT (5.268637698941997 42.747250193330856)"]
1271+
| EVAL location = TO_GEOPOINT(location)
1272+
| MV_EXPAND location
1273+
| WHERE ST_INTERSECTS(location, "81397ffffffffff"::geohex)
1274+
;
1275+
1276+
location:geo_point
1277+
POINT (2.475211258445467 41.32352174592337)
1278+
POINT (5.268637698941997 42.747250193330856)
1279+
;
1280+
1281+
gridGeohexLiteralFromCellDisjoint
1282+
required_capability: spatial_grid_intersects
1283+
1284+
ROW location = ["POINT (6.360728044651057 47.94084087577894)", "POINT (2.475211258445467 41.32352174592337)", "POINT (5.268637698941997 42.747250193330856)"]
1285+
| EVAL location = TO_GEOPOINT(location)
1286+
| MV_EXPAND location
1287+
| WHERE ST_DISJOINT(location, "81397ffffffffff"::geohex)
1288+
;
1289+
1290+
location:geo_point
1291+
POINT (6.360728044651057 47.94084087577894)
1292+
;
1293+
11261294
gridGeohexStatsByWhereUK
11271295
required_capability: spatial_grid_types
11281296

x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/SpatialDisjointGeoPointDocValuesAndConstantGridEvaluator.java

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)