Skip to content

Commit 88f27dc

Browse files
committed
Added more tests for geo_match in ES|QL ENRICH
This tests the fact that we can have geo_point in the enrich index and a geo_shape in the query (all other tests do the opposite). This also tests how the source index mapping for the points does not matter, can be geo_point, geo_shape or even keyword. The only requirement is that the actual fields are parsable as geo_shape during the geo_match enrich policy execution. They are being converted into a dedicated enrich index which always uses geo_shape as the mapping, regardless of the original mapping type. This is related to the recently reported issue at #138637
1 parent 3ed487c commit 88f27dc

File tree

4 files changed

+272
-0
lines changed

4 files changed

+272
-0
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvTestsDataLoader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ public class CsvTestsDataLoader {
253253
private static final EnrichConfig CITY_NAMES_ENRICH = new EnrichConfig("city_names", "enrich-policy-city_names.json");
254254
private static final EnrichConfig CITY_BOUNDARIES_ENRICH = new EnrichConfig("city_boundaries", "enrich-policy-city_boundaries.json");
255255
private static final EnrichConfig CITY_AIRPORTS_ENRICH = new EnrichConfig("city_airports", "enrich-policy-city_airports.json");
256+
private static final EnrichConfig CITY_LOCATIONS_ENRICH = new EnrichConfig("city_locations", "enrich-policy-city_locations.json");
256257
private static final EnrichConfig COLORS_ENRICH = new EnrichConfig("colors_policy", "enrich-policy-colors_cmyk.json");
257258

258259
public static final List<String> ENRICH_SOURCE_INDICES = List.of(
@@ -275,6 +276,7 @@ public class CsvTestsDataLoader {
275276
CITY_NAMES_ENRICH,
276277
CITY_BOUNDARIES_ENRICH,
277278
CITY_AIRPORTS_ENRICH,
279+
CITY_LOCATIONS_ENRICH,
278280
COLORS_ENRICH
279281
);
280282
public static final String NUMERIC_REGEX = "-?\\d+(\\.\\d+)?";
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"geo_match": {
3+
"indices": "airport_city_boundaries",
4+
"match_field": "city_location",
5+
"enrich_fields": ["abbrev", "airport", "region", "city", "city_boundary"]
6+
}
7+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,17 @@ C | 75 | BBOX (-107.51820000819862, 172.6055999379605, 55.7
866866
B | 69 | BBOX (-116.51340007781982, 153.2021999359131, 60.631899973377585, -41.20620000176132) | BBOX (-116.23080002143979, 153.02809992805123, 60.46669999603182, -41.1500000115484)
867867
;
868868

869+
enrichPolicyWithGeoPoint
870+
required_capability: enrich_load
871+
872+
ROW box = "POLYGON((11 55, 13 55, 13 56, 11 56, 11 55))"::geo_shape
873+
| ENRICH city_locations ON box WITH abbrev, airport, region, city
874+
;
875+
876+
box:geo_shape | abbrev:keyword | airport:text | region:text | city:keyword
877+
POLYGON ((11.0 55.0, 13.0 55.0, 13.0 56.0, 11.0 56.0, 11.0 55.0)) | CPH | Copenhagen | Københavns Kommune | Copenhagen
878+
;
879+
869880
###############################################
870881
# Tests for ST_INTERSECTS on GEO_POINT type
871882

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
---
2+
setup:
3+
- requires:
4+
cluster_features: [ "gte_v8.14.0" ]
5+
reason: "GEO_MATCH ENRICH support was added in 8.14.0"
6+
test_runner_features: allowed_warnings_regex
7+
8+
- do:
9+
indices.create:
10+
index: regions
11+
body:
12+
mappings:
13+
properties:
14+
shape:
15+
type: geo_shape
16+
region:
17+
type: keyword
18+
19+
- do:
20+
bulk:
21+
index: regions
22+
refresh: true
23+
body:
24+
- { "index": { } }
25+
- { "shape": "POLYGON ((12.453 55.7122, 12.4785 55.6563, 12.5332 55.6318, 12.5955 55.6802, 12.5963 55.7125, 12.6398 55.7224, 12.6022 55.7257, 12.5905 55.7097, 12.5659 55.7327, 12.453 55.7122), (12.4913 55.6791, 12.5381 55.6977, 12.5573 55.6817, 12.5233 55.6665, 12.4913 55.6791))", "region": "Copenhagen" }
26+
- { "index": { } }
27+
- { "shape": "POLYGON ((4.0 50.46, 4.01 50.46, 4.01 50.48, 4.0 50.48, 4.0 50.46))", "region": "Obourg" }
28+
29+
---
30+
"locations_geo_point_valid_shapes":
31+
- do:
32+
indices.create:
33+
index: locations
34+
body:
35+
settings:
36+
index.number_of_shards: 1
37+
index.routing.rebalance.enable: "none"
38+
mappings:
39+
properties:
40+
location:
41+
type: geo_point
42+
name:
43+
type: keyword
44+
45+
- do:
46+
bulk:
47+
index: locations
48+
refresh: true
49+
body:
50+
- { "index": { } }
51+
- { "location": { "type": "point","coordinates": [ 4.0053486386, 50.4697386503 ] }, "name": "GeoJSON" }
52+
- { "index": { } }
53+
- { "location": "POINT(4.0053486386 50.4697386503)", "name": "WKT" }
54+
55+
- do:
56+
enrich.put_policy:
57+
name: locations-policy
58+
body:
59+
geo_match:
60+
indices: [ "locations" ]
61+
match_field: "location"
62+
enrich_fields: [ "name", "location" ]
63+
64+
- do:
65+
enrich.execute_policy:
66+
name: locations-policy
67+
68+
- do:
69+
cluster.health:
70+
wait_for_no_initializing_shards: true
71+
wait_for_events: languid
72+
73+
- do:
74+
allowed_warnings_regex:
75+
- "No limit defined, adding default limit of \\[.*\\]"
76+
esql.query:
77+
body:
78+
query: 'FROM regions | ENRICH locations-policy ON shape'
79+
80+
- match: { columns.0.name: "region" }
81+
- match: { columns.0.type: "keyword" }
82+
- match: { columns.1.name: "shape" }
83+
- match: { columns.1.type: "geo_shape" }
84+
- match: { columns.2.name: "name" }
85+
- match: { columns.2.type: "keyword" }
86+
- match: { columns.3.name: "location" }
87+
- match: { columns.3.type: "geo_shape" }
88+
89+
- length: { values: 2 }
90+
- match: { values.0: [ "Copenhagen", "POLYGON ((12.453 55.7122, 12.4785 55.6563, 12.5332 55.6318, 12.5955 55.6802, 12.5963 55.7125, 12.6398 55.7224, 12.6022 55.7257, 12.5905 55.7097, 12.5659 55.7327, 12.453 55.7122), (12.4913 55.6791, 12.5381 55.6977, 12.5573 55.6817, 12.5233 55.6665, 12.4913 55.6791))", null, null ] }
91+
- match: { values.1: [ "Obourg", "POLYGON ((4.0 50.46, 4.01 50.46, 4.01 50.48, 4.0 50.48, 4.0 50.46))", ["GeoJSON", "WKT"], ["POINT (4.0053486386 50.4697386503)", "POINT (4.0053486386 50.4697386503)"] ] }
92+
93+
- do:
94+
enrich.delete_policy:
95+
name: locations-policy
96+
97+
---
98+
"locations_keyword_valid_shapes":
99+
100+
- do:
101+
indices.create:
102+
index: locations
103+
body:
104+
settings:
105+
index.number_of_shards: 1
106+
index.routing.rebalance.enable: "none"
107+
mappings:
108+
properties:
109+
location:
110+
type: keyword
111+
name:
112+
type: keyword
113+
114+
- do:
115+
bulk:
116+
index: locations
117+
refresh: true
118+
body:
119+
- { "index": { } }
120+
- { "location": "POINT(4.0053486386 50.4697386503)", "name": "WKT" }
121+
122+
- do:
123+
enrich.put_policy:
124+
name: locations-policy
125+
body:
126+
geo_match:
127+
indices: [ "locations" ]
128+
match_field: "location"
129+
enrich_fields: [ "name", "location" ]
130+
131+
- do:
132+
enrich.execute_policy:
133+
name: locations-policy
134+
135+
- do:
136+
cluster.health:
137+
wait_for_no_initializing_shards: true
138+
wait_for_events: languid
139+
140+
- do:
141+
allowed_warnings_regex:
142+
- "No limit defined, adding default limit of \\[.*\\]"
143+
esql.query:
144+
body:
145+
query: 'FROM regions | ENRICH locations-policy ON shape'
146+
147+
- match: { columns.0.name: "region" }
148+
- match: { columns.0.type: "keyword" }
149+
- match: { columns.1.name: "shape" }
150+
- match: { columns.1.type: "geo_shape" }
151+
- match: { columns.2.name: "name" }
152+
- match: { columns.2.type: "keyword" }
153+
- match: { columns.3.name: "location" }
154+
- match: { columns.3.type: "geo_shape" }
155+
156+
- length: { values: 2 }
157+
- match: { values.0: [ "Copenhagen", "POLYGON ((12.453 55.7122, 12.4785 55.6563, 12.5332 55.6318, 12.5955 55.6802, 12.5963 55.7125, 12.6398 55.7224, 12.6022 55.7257, 12.5905 55.7097, 12.5659 55.7327, 12.453 55.7122), (12.4913 55.6791, 12.5381 55.6977, 12.5573 55.6817, 12.5233 55.6665, 12.4913 55.6791))", null, null ] }
158+
- match: { values.1: [ "Obourg", "POLYGON ((4.0 50.46, 4.01 50.46, 4.01 50.48, 4.0 50.48, 4.0 50.46))", "WKT", "POINT (4.0053486386 50.4697386503)" ] }
159+
160+
- do:
161+
enrich.delete_policy:
162+
name: locations-policy
163+
164+
---
165+
"locations_geo_point_invalid_shapes":
166+
- do:
167+
indices.create:
168+
index: locations
169+
body:
170+
settings:
171+
index.number_of_shards: 1
172+
index.routing.rebalance.enable: "none"
173+
mappings:
174+
properties:
175+
location:
176+
type: geo_point
177+
name:
178+
type: keyword
179+
180+
- do:
181+
bulk:
182+
index: locations
183+
refresh: true
184+
body:
185+
- { "index": { } }
186+
- { "location": { "type": "point","coordinates": [ 4.0053486386, 50.4697386503 ] }, "name": "GeoJSON" }
187+
- { "index": { } }
188+
- { "location": "POINT(4.0053486386 50.4697386503)", "name": "WKT" }
189+
- { "index": { } }
190+
- { "location": { "lon": 4.0053486386, "lat": 50.4697386503 }, "name": "Object(lat,lon)" }
191+
192+
- do:
193+
enrich.put_policy:
194+
name: locations-policy
195+
body:
196+
geo_match:
197+
indices: [ "locations" ]
198+
match_field: "location"
199+
enrich_fields: [ "name", "location" ]
200+
201+
- do:
202+
catch: "/Encountered bulk failures during reindex process/"
203+
enrich.execute_policy:
204+
name: locations-policy
205+
206+
- do:
207+
enrich.delete_policy:
208+
name: locations-policy
209+
210+
---
211+
"locations_keyword_invalid_shapes":
212+
- do:
213+
indices.create:
214+
index: locations
215+
body:
216+
settings:
217+
index.number_of_shards: 1
218+
index.routing.rebalance.enable: "none"
219+
mappings:
220+
properties:
221+
location:
222+
type: keyword
223+
name:
224+
type: keyword
225+
226+
- do:
227+
bulk:
228+
index: locations
229+
refresh: true
230+
body:
231+
- { "index": { } }
232+
- { "location": "POINT(4.0053486386 50.4697386503)", "name": "WKT" }
233+
- { "index": { } }
234+
- { "location": "50.4697386503,4.0053486386", "name": "lat,lon" }
235+
236+
- do:
237+
enrich.put_policy:
238+
name: locations-policy
239+
body:
240+
geo_match:
241+
indices: [ "locations" ]
242+
match_field: "location"
243+
enrich_fields: [ "name", "location" ]
244+
245+
- do:
246+
catch: "/Encountered bulk failures during reindex process/"
247+
enrich.execute_policy:
248+
name: locations-policy
249+
250+
- do:
251+
enrich.delete_policy:
252+
name: locations-policy

0 commit comments

Comments
 (0)