Skip to content

Commit a497c21

Browse files
authored
REST tests for bucket_script agg (#94749)
Some fairly basic tests for the bucket_script agg that'll cover us for some forwards and backwards compatibility tests.
1 parent af96109 commit a497c21

File tree

1 file changed

+342
-0
lines changed
  • modules/aggregations/src/yamlRestTest/resources/rest-api-spec/test/aggregations

1 file changed

+342
-0
lines changed
Lines changed: 342 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,342 @@
1+
setup:
2+
- do:
3+
bulk:
4+
index: test
5+
refresh: true
6+
body:
7+
- { "index": { } }
8+
- { "a": 2, "b": 12, "c": 21, "gappy": 99 }
9+
- { "index": { } }
10+
- { "a": 3, "b": 56, "c": 12 }
11+
- { "index": { } }
12+
- { "a": 4, "b": 82, "c": 13, "gappy": 98 }
13+
- { "index": { } }
14+
- { "a": 5, "b": 12, "c": 54 }
15+
16+
---
17+
calculate:
18+
- do:
19+
search:
20+
body:
21+
aggs:
22+
a:
23+
histogram:
24+
field: a
25+
interval: 1
26+
aggs:
27+
b:
28+
sum:
29+
field: b
30+
c:
31+
sum:
32+
field: c
33+
d:
34+
bucket_script:
35+
buckets_path:
36+
b: b
37+
c: c
38+
script: params.b + params.c
39+
- length: { aggregations.a.buckets: 4 }
40+
- match: { aggregations.a.buckets.0.d.value: 33.0 }
41+
- match: { aggregations.a.buckets.1.d.value: 68.0 }
42+
- match: { aggregations.a.buckets.2.d.value: 95.0 }
43+
- match: { aggregations.a.buckets.3.d.value: 66.0 }
44+
45+
---
46+
input is unmapped sum:
47+
- do:
48+
search:
49+
body:
50+
aggs:
51+
a:
52+
histogram:
53+
field: a
54+
interval: 1
55+
aggs:
56+
b:
57+
sum:
58+
field: b
59+
unmapped:
60+
sum:
61+
field: unmapped
62+
d:
63+
bucket_script:
64+
buckets_path:
65+
b: b
66+
unmapped: unmapped
67+
script: params.b + params.unmapped
68+
# sum(unmapped) is 0
69+
- length: { aggregations.a.buckets: 4 }
70+
- match: { aggregations.a.buckets.0.d.value: 12.0 }
71+
- match: { aggregations.a.buckets.1.d.value: 56.0 }
72+
- match: { aggregations.a.buckets.2.d.value: 82.0 }
73+
- match: { aggregations.a.buckets.3.d.value: 12.0 }
74+
75+
---
76+
input is unmapped avg:
77+
- do:
78+
search:
79+
body:
80+
aggs:
81+
a:
82+
histogram:
83+
field: a
84+
interval: 1
85+
aggs:
86+
b:
87+
avg:
88+
field: b
89+
unmapped:
90+
avg:
91+
field: unmapped
92+
d:
93+
bucket_script:
94+
buckets_path:
95+
b: b
96+
unmapped: unmapped
97+
script: params.b + params.unmapped
98+
# unmapped avg is null which is skipped
99+
- length: { aggregations.a.buckets: 4 }
100+
- is_false: aggregations.a.buckets.0.d
101+
- is_false: aggregations.a.buckets.1.d
102+
- is_false: aggregations.a.buckets.2.d
103+
- is_false: aggregations.a.buckets.3.d
104+
105+
---
106+
params:
107+
- do:
108+
search:
109+
body:
110+
aggs:
111+
a:
112+
histogram:
113+
field: a
114+
interval: 1
115+
aggs:
116+
b:
117+
sum:
118+
field: b
119+
c:
120+
sum:
121+
field: c
122+
d:
123+
bucket_script:
124+
buckets_path:
125+
b: b
126+
script:
127+
source: params.b + params.extra
128+
params:
129+
extra: 1
130+
- length: { aggregations.a.buckets: 4 }
131+
- match: { aggregations.a.buckets.0.d.value: 13.0 }
132+
- match: { aggregations.a.buckets.1.d.value: 57.0 }
133+
- match: { aggregations.a.buckets.2.d.value: 83.0 }
134+
- match: { aggregations.a.buckets.3.d.value: 13.0 }
135+
136+
---
137+
default gap_policy is skip:
138+
- do:
139+
search:
140+
body:
141+
aggs:
142+
a:
143+
histogram:
144+
field: a
145+
interval: 1
146+
aggs:
147+
b:
148+
sum:
149+
field: b
150+
gappy:
151+
sum:
152+
field: gappy
153+
d:
154+
bucket_script:
155+
buckets_path:
156+
b: b
157+
gappy: gappy
158+
script: params.b + params.gappy
159+
- length: { aggregations.a.buckets: 4 }
160+
- match: { aggregations.a.buckets.0.d.value: 111.0 }
161+
- match: { aggregations.a.buckets.1.d.value: 56.0 }
162+
- match: { aggregations.a.buckets.2.d.value: 180.0 }
163+
- match: { aggregations.a.buckets.3.d.value: 12.0 }
164+
165+
---
166+
gap_policy is skip:
167+
- do:
168+
search:
169+
body:
170+
aggs:
171+
a:
172+
histogram:
173+
field: a
174+
interval: 1
175+
aggs:
176+
b:
177+
sum:
178+
field: b
179+
gappy:
180+
sum:
181+
field: gappy
182+
d:
183+
bucket_script:
184+
gap_policy: skip
185+
buckets_path:
186+
b: b
187+
gappy: gappy
188+
script: params.b + params.gappy
189+
- length: { aggregations.a.buckets: 4 }
190+
- match: { aggregations.a.buckets.0.d.value: 111.0 }
191+
- match: { aggregations.a.buckets.1.d.value: 56.0 }
192+
- match: { aggregations.a.buckets.2.d.value: 180.0 }
193+
- match: { aggregations.a.buckets.3.d.value: 12.0 }
194+
195+
---
196+
gap_policy is insert_zeros:
197+
- do:
198+
search:
199+
body:
200+
aggs:
201+
a:
202+
histogram:
203+
field: a
204+
interval: 1
205+
aggs:
206+
b:
207+
sum:
208+
field: b
209+
gappy:
210+
sum:
211+
field: gappy
212+
d:
213+
bucket_script:
214+
gap_policy: insert_zeros
215+
buckets_path:
216+
b: b
217+
gappy: gappy
218+
script: params.b + params.gappy
219+
- length: { aggregations.a.buckets: 4 }
220+
- match: { aggregations.a.buckets.0.d.value: 111.0 }
221+
- match: { aggregations.a.buckets.1.d.value: 56.0 }
222+
- match: { aggregations.a.buckets.2.d.value: 180.0 }
223+
- match: { aggregations.a.buckets.3.d.value: 12.0 }
224+
225+
---
226+
gap_policy is keep_values:
227+
- do:
228+
search:
229+
body:
230+
aggs:
231+
a:
232+
histogram:
233+
field: a
234+
interval: 1
235+
aggs:
236+
b:
237+
sum:
238+
field: b
239+
gappy:
240+
sum:
241+
field: gappy
242+
d:
243+
bucket_script:
244+
gap_policy: keep_values
245+
buckets_path:
246+
b: b
247+
gappy: gappy
248+
script: params.b + params.gappy
249+
- length: { aggregations.a.buckets: 4 }
250+
- match: { aggregations.a.buckets.0.d.value: 111.0 }
251+
- match: { aggregations.a.buckets.1.d.value: 56.0 }
252+
- match: { aggregations.a.buckets.2.d.value: 180.0 }
253+
- match: { aggregations.a.buckets.3.d.value: 12.0 }
254+
255+
---
256+
format:
257+
- do:
258+
search:
259+
body:
260+
aggs:
261+
a:
262+
histogram:
263+
field: a
264+
interval: 1
265+
aggs:
266+
b:
267+
sum:
268+
field: b
269+
gappy:
270+
sum:
271+
field: gappy
272+
d:
273+
bucket_script:
274+
format: "000.00"
275+
buckets_path:
276+
b: b
277+
gappy: gappy
278+
script: params.b + params.gappy
279+
- length: { aggregations.a.buckets: 4 }
280+
- match: { aggregations.a.buckets.0.d.value: 111.0 }
281+
- match: { aggregations.a.buckets.1.d.value: 56.0 }
282+
- match: { aggregations.a.buckets.2.d.value: 180.0 }
283+
- match: { aggregations.a.buckets.3.d.value: 12.0 }
284+
- match: { aggregations.a.buckets.0.d.value_as_string: "111.00" }
285+
- match: { aggregations.a.buckets.1.d.value_as_string: "056.00" }
286+
- match: { aggregations.a.buckets.2.d.value_as_string: "180.00" }
287+
- match: { aggregations.a.buckets.3.d.value_as_string: "012.00" }
288+
289+
---
290+
bad script:
291+
- do:
292+
catch: /NullPointerException/
293+
search:
294+
body:
295+
aggs:
296+
a:
297+
histogram:
298+
field: a
299+
interval: 1
300+
aggs:
301+
b:
302+
sum:
303+
field: b
304+
d:
305+
bucket_script:
306+
buckets_path:
307+
b: b
308+
script: params.garbage + 12
309+
310+
---
311+
invalid path:
312+
- do:
313+
catch: /No aggregation found for path \[missing\]/
314+
search:
315+
body:
316+
aggs:
317+
a:
318+
histogram:
319+
field: a
320+
interval: 1
321+
aggs:
322+
d:
323+
bucket_script:
324+
buckets_path:
325+
missing: missing
326+
script: params.missing + 12
327+
328+
---
329+
top level fails:
330+
- do:
331+
catch: /bucket_script aggregation \[d\] must be declared inside of another aggregation/
332+
search:
333+
body:
334+
aggs:
335+
b:
336+
sum:
337+
field: b
338+
d:
339+
bucket_script:
340+
buckets_path:
341+
b: b
342+
script: params.b + 12

0 commit comments

Comments
 (0)