Skip to content

Commit 56e50ab

Browse files
Enhanced REST tests for geo and cartesian centroid (#94964)
* Enhanced REST tests for geo and cartesian centroid Coverage increased to cover cases for: * centroid over points * centroid over shapes * centroid over points with filter * centroid over shapes with filter * centroid over points with grouping * centroid over shapes with grouping * centroid over shapes with grouping and filter The last one was not done for points because the purpose of that test was primarily to validate the shape rules where centroids over GEOMETRYCOLLECTION would use only the highest dimensionality geometries for centroid calculation. * Enforce single shard So reduce risk of flakiness in aggregating over multiple documents
1 parent 9a673ad commit 56e50ab

File tree

3 files changed

+596
-109
lines changed

3 files changed

+596
-109
lines changed
Lines changed: 297 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,297 @@
1+
setup:
2+
- skip:
3+
features: close_to
4+
5+
- do:
6+
indices.create:
7+
index: locations
8+
body:
9+
mappings:
10+
properties:
11+
location:
12+
type: shape
13+
city:
14+
type: keyword
15+
name:
16+
type: keyword
17+
18+
- do:
19+
bulk:
20+
refresh: true
21+
index: locations
22+
body: |
23+
{"index":{}}
24+
{"location": "POINT(488.9187 5237.3184)", "city": "Amsterdam", "name": "Royal Palace Amsterdam"}
25+
{"index":{}}
26+
{"location": "POINT(488.5057 5237.0159)", "city": "Amsterdam", "name": "The Amsterdam Dungeon"}
27+
{"index":{}}
28+
{"location": "POINT(490.1618 5236.9219)", "city": "Amsterdam", "name": "Museum Het Rembrandthuis"}
29+
{"index":{}}
30+
{"location": "POINT(491.2350 5237.4081)", "city": "Amsterdam", "name": "NEMO Science Museum"}
31+
{"index":{}}
32+
{"location": "POINT(491.4722 5237.1667)", "city": "Amsterdam", "name": "Nederlands Scheepvaartmuseum"}
33+
{"index":{}}
34+
{"location": "POINT(488.394 5237.52)", "city": "Amsterdam", "name": "Anne Frank House"}
35+
{"index":{}}
36+
{"location": "POINT(440.5200 5122.2900)", "city": "Antwerp", "name": "Letterenhuis"}
37+
{"index":{}}
38+
{"location": "POINT(233.6389 4886.1111)", "city": "Paris", "name": "Musée du Louvre"}
39+
{"index":{}}
40+
{"location": "POINT(232.7000 4886.0000)", "city": "Paris", "name": "Musée dOrsay"}
41+
42+
- do:
43+
indices.create:
44+
index: shapes
45+
body:
46+
mappings:
47+
properties:
48+
shape:
49+
type: shape
50+
category:
51+
type: keyword
52+
name:
53+
type: keyword
54+
55+
- do:
56+
bulk:
57+
refresh: true
58+
index: shapes
59+
body: |
60+
{"index":{}}
61+
{"shape": "POINT(488.9187 5237.3184)", "category": "points", "name": "Royal Palace Amsterdam"}
62+
{"index":{}}
63+
{"shape": "POINT(488.5057 5237.0159)", "category": "points", "name": "The Amsterdam Dungeon"}
64+
{"index":{}}
65+
{"shape": "POINT(490.1618 5236.9219)", "category": "points", "name": "Museum Het Rembrandthuis"}
66+
{"index":{}}
67+
{"shape": "POINT(491.2350 5237.4081)", "category": "points", "name": "NEMO Science Museum"}
68+
{"index":{}}
69+
{"shape": "POINT(491.4722 5237.1667)", "category": "points", "name": "Nederlands Scheepvaartmuseum"}
70+
{"index":{}}
71+
{"shape": "POINT(488.394 5237.52)", "category": "points", "name": "Anne Frank House"}
72+
{"index":{}}
73+
{"shape": "LINESTRING(491.4722 5237.1667, 488.9187 5237.3184)", "category": "linestrings", "name": "Path of: Nederlands Scheepvaartmuseum, Royal Palace Amsterdam"}
74+
{"index":{}}
75+
{"shape": "LINESTRING(490.1618 5236.9219, 491.2350 5237.4081, 491.4722 5237.1667)", "category": "linestrings", "name": "Path of: Museum Het Rembrandthuis, NEMO Science Museum, Nederlands Scheepvaartmuseum"}
76+
{"index":{}}
77+
{"shape": "LINESTRING(488.9187 5237.3184, 488.5057 5237.0159, 490.1618 5236.9219, 491.2350 5237.4081, 491.4722 5237.1667)", "category": "linestrings", "name": "Path of: Royal Palace Amsterdam, The Amsterdam Dungeon, Museum Het Rembrandthuis, NEMO Science Museum, Nederlands Scheepvaartmuseum"}
78+
{"index":{}}
79+
{"shape": "POLYGON((488.9187 5237.3184, 488.5057 5237.0159, 490.1618 5236.9219, 491.4722 5237.1667, 491.2350 5237.4081, 488.9187 5237.3184))", "category": "polygons", "name": "Area of: Royal Palace Amsterdam, The Amsterdam Dungeon, Museum Het Rembrandthuis, Nederlands Scheepvaartmuseum, NEMO Science Museum"}
80+
{"index":{}}
81+
{"shape": "POLYGON((488.35 5237.50, 488.44 5237.50, 488.44 5237.54, 488.35 5237.54, 488.35 5237.50))", "category": "polygons", "name": "Box around: Anne Frank House"}
82+
{"index":{}}
83+
{"shape": "MULTIPOLYGON(((488.9187 5237.3184, 488.5057 5237.0159, 490.1618 5236.9219, 491.4722 5237.1667, 491.2350 5237.4081, 488.9187 5237.3184)), ((488.35 5237.50, 488.44 5237.50, 488.44 5237.54, 488.35 5237.54, 488.35 5237.50)))", "category": "multipolygons", "name": "Two areas"}
84+
{"index":{}}
85+
{"shape": "GEOMETRYCOLLECTION(POINT(488.394 5237.52), LINESTRING(488.9187 5237.3184, 488.5057 5237.0159, 490.1618 5236.9219, 491.2350 5237.4081, 491.4722 5237.1667), POLYGON((488.35 5237.50, 488.44 5237.50, 488.44 5237.54, 488.35 5237.54, 488.35 5237.50)), MULTIPOLYGON(((488.9187 5237.3184, 488.5057 5237.0159, 490.1618 5236.9219, 491.4722 5237.1667, 491.2350 5237.4081, 488.9187 5237.3184)), ((488.35 5237.50, 488.44 5237.50, 488.44 5237.54, 488.35 5237.54, 488.35 5237.50))))", "category": "collections", "name": "Collection of point, line, polygon and multipolygon"}
86+
{"index":{}}
87+
{"shape": "GEOMETRYCOLLECTION(POINT(488.394 5237.52), LINESTRING(488.9187 5237.3184, 488.5057 5237.0159, 490.1618 5236.9219, 491.2350 5237.4081, 491.4722 5237.1667), POLYGON((488.35 5237.50, 488.44 5237.50, 488.44 5237.54, 488.35 5237.54, 488.35 5237.50)))", "category": "collections", "name": "Collection of point, line and polygon"}
88+
{"index":{}}
89+
{"shape": "GEOMETRYCOLLECTION(POINT(488.394 5237.52), LINESTRING(488.9187 5237.3184, 488.5057 5237.0159, 490.1618 5236.9219, 491.2350 5237.4081, 491.4722 5237.1667))", "category": "collections", "name": "Collection of point and line"}
90+
{"index":{}}
91+
{"shape": "GEOMETRYCOLLECTION(POINT(488.394 5237.52))", "category": "collections", "name": "Collection of one point"}
92+
{"index":{}}
93+
{"shape": "GEOMETRYCOLLECTION(POINT(488.394 5237.52), POINT(488.9187 5237.3184))", "category": "collections", "name": "Collection of two points"}
94+
95+
- do:
96+
indices.refresh: { }
97+
98+
---
99+
"Test cartesian_centroid aggregation on cartesian shape points":
100+
- do:
101+
search:
102+
rest_total_hits_as_int: true
103+
index: locations
104+
size: 0
105+
body:
106+
aggs:
107+
centroid:
108+
cartesian_centroid:
109+
field: location
110+
- match: { hits.total: 9 }
111+
- match: { aggregations.centroid.count: 9 }
112+
- close_to: { aggregations.centroid.location.x: { value: 427.2829, error: 0.0001 } }
113+
- close_to: { aggregations.centroid.location.y: { value: 5146.4169, error: 0.0001 } }
114+
115+
---
116+
"Test cartesian_centroid aggregation on cartesian shape shapes":
117+
- do:
118+
search:
119+
rest_total_hits_as_int: true
120+
index: shapes
121+
size: 0
122+
body:
123+
aggs:
124+
centroid:
125+
cartesian_centroid:
126+
field: shape
127+
- match: { hits.total: 17 }
128+
- match: { aggregations.centroid.count: 17 }
129+
- close_to: { aggregations.centroid.location.x: { value: 490.0065, error: 0.0001 } }
130+
- close_to: { aggregations.centroid.location.y: { value: 5237.1722, error: 0.0001 } }
131+
132+
---
133+
"Test cartesian_centroid aggregation on cartesian shape points with filter":
134+
- do:
135+
search:
136+
rest_total_hits_as_int: true
137+
index: locations
138+
size: 0
139+
body:
140+
query:
141+
term:
142+
city: "Amsterdam"
143+
aggs:
144+
centroid:
145+
cartesian_centroid:
146+
field: location
147+
- match: { hits.total: 6 }
148+
- match: { aggregations.centroid.count: 6 }
149+
- close_to: { aggregations.centroid.location.x: { value: 489.7812, error: 0.0001 } }
150+
- close_to: { aggregations.centroid.location.y: { value: 5237.2252, error: 0.0001 } }
151+
152+
---
153+
"Test cartesian_centroid aggregation on cartesian shape shapes with filter":
154+
- do:
155+
search:
156+
rest_total_hits_as_int: true
157+
index: shapes
158+
size: 0
159+
body:
160+
query:
161+
term:
162+
category: "points"
163+
aggs:
164+
centroid:
165+
cartesian_centroid:
166+
field: shape
167+
- match: { hits.total: 6 }
168+
- match: { aggregations.centroid.count: 6 }
169+
- close_to: { aggregations.centroid.location.x: { value: 489.7812, error: 0.0001 } }
170+
- close_to: { aggregations.centroid.location.y: { value: 5237.2252, error: 0.0001 } }
171+
172+
---
173+
"Test cartesian_centroid aggregation on cartesian shape points with grouping":
174+
- do:
175+
search:
176+
rest_total_hits_as_int: true
177+
index: locations
178+
size: 0
179+
body:
180+
aggs:
181+
cities:
182+
terms:
183+
field: "city"
184+
aggs:
185+
centroid:
186+
cartesian_centroid:
187+
field: location
188+
- match: { hits.total: 9 }
189+
- length: { aggregations.cities.buckets: 3 }
190+
- match: { aggregations.cities.buckets.0.key: "Amsterdam" }
191+
- match: { aggregations.cities.buckets.0.doc_count: 6 }
192+
- match: { aggregations.cities.buckets.0.centroid.count: 6 }
193+
- close_to: { aggregations.cities.buckets.0.centroid.location.x: { value: 489.7812, error: 0.0001 } }
194+
- close_to: { aggregations.cities.buckets.0.centroid.location.y: { value: 5237.2252, error: 0.0001 } }
195+
- match: { aggregations.cities.buckets.1.key: "Paris" }
196+
- match: { aggregations.cities.buckets.1.doc_count: 2 }
197+
- match: { aggregations.cities.buckets.1.centroid.count: 2 }
198+
- close_to: { aggregations.cities.buckets.1.centroid.location.x: { value: 233.1694, error: 0.0001 } }
199+
- close_to: { aggregations.cities.buckets.1.centroid.location.y: { value: 4886.0557, error: 0.0001 } }
200+
- match: { aggregations.cities.buckets.2.key: "Antwerp" }
201+
- match: { aggregations.cities.buckets.2.doc_count: 1 }
202+
- match: { aggregations.cities.buckets.2.centroid.count: 1 }
203+
- close_to: { aggregations.cities.buckets.2.centroid.location.x: { value: 440.5200, error: 0.0001 } }
204+
- close_to: { aggregations.cities.buckets.2.centroid.location.y: { value: 5122.2900, error: 0.0001 } }
205+
206+
---
207+
"Test cartesian_centroid aggregation on cartesian shape shapes with grouping":
208+
- do:
209+
search:
210+
rest_total_hits_as_int: true
211+
index: shapes
212+
size: 0
213+
body:
214+
aggs:
215+
categories:
216+
terms:
217+
field: "category"
218+
aggs:
219+
centroid:
220+
cartesian_centroid:
221+
field: shape
222+
- match: { hits.total: 17 }
223+
- length: { aggregations.categories.buckets: 5 }
224+
- match: { aggregations.categories.buckets.0.key: "points" }
225+
- match: { aggregations.categories.buckets.0.doc_count: 6 }
226+
- match: { aggregations.categories.buckets.0.centroid.count: 6 }
227+
- close_to: { aggregations.categories.buckets.0.centroid.location.x: { value: 489.7812, error: 0.0001 } }
228+
- close_to: { aggregations.categories.buckets.0.centroid.location.y: { value: 5237.2252, error: 0.0001 } }
229+
- match: { aggregations.categories.buckets.1.key: "collections" }
230+
- match: { aggregations.categories.buckets.1.doc_count: 5 }
231+
- match: { aggregations.categories.buckets.1.centroid.count: 5 }
232+
- close_to: { aggregations.categories.buckets.1.centroid.location.x: { value: 489.9987, error: 0.0001 } }
233+
- close_to: { aggregations.categories.buckets.1.centroid.location.y: { value: 5237.1741, error: 0.0001 } }
234+
- match: { aggregations.categories.buckets.2.key: "linestrings" }
235+
- match: { aggregations.categories.buckets.2.doc_count: 3 }
236+
- match: { aggregations.categories.buckets.2.centroid.count: 3 }
237+
- close_to: { aggregations.categories.buckets.2.centroid.location.x: { value: 490.1672, error: 0.0001 } }
238+
- close_to: { aggregations.categories.buckets.2.centroid.location.y: { value: 5237.1595, error: 0.0001 } }
239+
- match: { aggregations.categories.buckets.3.key: "polygons" }
240+
- match: { aggregations.categories.buckets.3.doc_count: 2 }
241+
- match: { aggregations.categories.buckets.3.centroid.count: 2 }
242+
- close_to: { aggregations.categories.buckets.3.centroid.location.x: { value: 490.0105, error: 0.0001 } }
243+
- close_to: { aggregations.categories.buckets.3.centroid.location.y: { value: 5237.1712, error: 0.0001 } }
244+
- match: { aggregations.categories.buckets.4.key: "multipolygons" }
245+
- match: { aggregations.categories.buckets.4.doc_count: 1 }
246+
- match: { aggregations.categories.buckets.4.centroid.count: 1 }
247+
- close_to: { aggregations.categories.buckets.4.centroid.location.x: { value: 490.0105, error: 0.0001 } }
248+
- close_to: { aggregations.categories.buckets.4.centroid.location.y: { value: 5237.1714, error: 0.0001 } }
249+
250+
---
251+
"Test cartesian_centroid aggregation on cartesian shape shapes with grouping and filter":
252+
- do:
253+
search:
254+
rest_total_hits_as_int: true
255+
index: shapes
256+
size: 0
257+
body:
258+
query:
259+
term:
260+
category: "collections"
261+
aggs:
262+
names:
263+
terms:
264+
field: "name"
265+
order:
266+
_key: "asc"
267+
aggs:
268+
centroid:
269+
cartesian_centroid:
270+
field: shape
271+
- match: { hits.total: 5 }
272+
- length: { aggregations.names.buckets: 5 }
273+
- match: { aggregations.names.buckets.0.key: "Collection of one point" }
274+
- match: { aggregations.names.buckets.0.doc_count: 1 }
275+
- match: { aggregations.names.buckets.0.centroid.count: 1 }
276+
- close_to: { aggregations.names.buckets.0.centroid.location.x: { value: 488.394, error: 0.0001 } }
277+
- close_to: { aggregations.names.buckets.0.centroid.location.y: { value: 5237.5200, error: 0.0001 } }
278+
- match: { aggregations.names.buckets.1.key: "Collection of point and line" }
279+
- match: { aggregations.names.buckets.1.doc_count: 1 }
280+
- match: { aggregations.names.buckets.1.centroid.count: 1 }
281+
- close_to: { aggregations.names.buckets.1.centroid.location.x: { value: 489.86888, error: 0.0001 } }
282+
- close_to: { aggregations.names.buckets.1.centroid.location.y: { value: 5237.0883, error: 0.0001 } }
283+
- match: { aggregations.names.buckets.2.key: "Collection of point, line and polygon" }
284+
- match: { aggregations.names.buckets.2.doc_count: 1 }
285+
- match: { aggregations.names.buckets.2.centroid.count: 1 }
286+
- close_to: { aggregations.names.buckets.2.centroid.location.x: { value: 488.395, error: 0.0001 } }
287+
- close_to: { aggregations.names.buckets.2.centroid.location.y: { value: 5237.5201, error: 0.0001 } }
288+
- match: { aggregations.names.buckets.3.key: "Collection of point, line, polygon and multipolygon" }
289+
- match: { aggregations.names.buckets.3.doc_count: 1 }
290+
- match: { aggregations.names.buckets.3.centroid.count: 1 }
291+
- close_to: { aggregations.names.buckets.3.centroid.location.x: { value: 490.0046, error: 0.0001 } }
292+
- close_to: { aggregations.names.buckets.3.centroid.location.y: { value: 5237.1729, error: 0.0001 } }
293+
- match: { aggregations.names.buckets.4.key: "Collection of two points" }
294+
- match: { aggregations.names.buckets.4.doc_count: 1 }
295+
- match: { aggregations.names.buckets.4.centroid.count: 1 }
296+
- close_to: { aggregations.names.buckets.4.centroid.location.x: { value: 488.6563, error: 0.0001 } }
297+
- close_to: { aggregations.names.buckets.4.centroid.location.y: { value: 5237.4194, error: 0.0001 } }

0 commit comments

Comments
 (0)