Skip to content

Commit d74b45b

Browse files
authored
REST tests for stats_bucket aggs (#87006)
Adds REST tests for `stats_bucket` and `extended_stats_bucket` aggs. Relates to #26220
1 parent 48ab87f commit d74b45b

File tree

2 files changed

+427
-0
lines changed

2 files changed

+427
-0
lines changed
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
setup:
2+
- do:
3+
bulk:
4+
index: no_gaps
5+
refresh: true
6+
body:
7+
- { "index": { } }
8+
- { "@timestamp": "2022-01-01T00:00:00", "v": 1 }
9+
- { "index": { } }
10+
- { "@timestamp": "2022-01-01T01:00:00", "v": 2 }
11+
- { "index": { } }
12+
- { "@timestamp": "2022-01-01T02:00:00", "v": 1 }
13+
14+
- do:
15+
bulk:
16+
index: gaps
17+
refresh: true
18+
body:
19+
- { "index": { } }
20+
- { "@timestamp": "2022-01-01T00:00:00", "v": 1 }
21+
- { "index": { } }
22+
- { "@timestamp": "2022-01-01T02:00:00", "v": 2 }
23+
- { "index": { } }
24+
- { "@timestamp": "2022-01-01T03:00:00", "v": 1 }
25+
26+
---
27+
basic:
28+
- skip:
29+
features: close_to
30+
31+
- do:
32+
search:
33+
index: no_gaps
34+
body:
35+
size: 0
36+
aggs:
37+
"@timestamp":
38+
date_histogram:
39+
field: "@timestamp"
40+
fixed_interval: 1h
41+
aggs:
42+
v: {avg: {field: v}}
43+
d:
44+
extended_stats_bucket:
45+
buckets_path: "@timestamp>v"
46+
- match: { hits.total.value: 3 }
47+
- length: { [email protected]: 3 }
48+
- match: { aggregations.d.count: 3 }
49+
- match: { aggregations.d.min: 1 }
50+
- match: { aggregations.d.max: 2 }
51+
- close_to: { aggregations.d.avg: {value: 1.333, error: 0.0005 }}
52+
- match: { aggregations.d.sum: 4.0 }
53+
- match: { aggregations.d.sum_of_squares: 6.0 }
54+
- close_to: { aggregations.d.variance: {value: 0.222, error: 0.0005 }}
55+
- close_to: { aggregations.d.variance_population: {value: 0.222, error: 0.0005 }}
56+
- close_to: { aggregations.d.variance_sampling: {value: 0.333, error: 0.0005 }}
57+
- close_to: { aggregations.d.std_deviation: {value: 0.471, error: 0.0005 }}
58+
- close_to: { aggregations.d.std_deviation_population: {value: 0.471, error: 0.0005 }}
59+
- close_to: { aggregations.d.std_deviation_sampling: {value: 0.577, error: 0.0005 }}
60+
- close_to: { aggregations.d.std_deviation_bounds.upper: {value: 2.276, error: 0.0005 }}
61+
- close_to: { aggregations.d.std_deviation_bounds.lower: {value: 0.391, error: 0.0005 }}
62+
- close_to: { aggregations.d.std_deviation_bounds.upper_population: {value: 2.276, error: 0.0005 }}
63+
- close_to: { aggregations.d.std_deviation_bounds.lower_population: {value: 0.391, error: 0.0005 }}
64+
- close_to: { aggregations.d.std_deviation_bounds.upper_sampling: {value: 2.488, error: 0.0005 }}
65+
- close_to: { aggregations.d.std_deviation_bounds.lower_sampling: {value: 0.179, error: 0.0005 }}
66+
67+
---
68+
format:
69+
- skip:
70+
features: close_to
71+
72+
- do:
73+
search:
74+
index: no_gaps
75+
body:
76+
size: 0
77+
aggs:
78+
"@timestamp":
79+
date_histogram:
80+
field: "@timestamp"
81+
fixed_interval: 1h
82+
aggs:
83+
v: {avg: {field: v}}
84+
d:
85+
extended_stats_bucket:
86+
buckets_path: "@timestamp>v"
87+
format: "0.00"
88+
- match: { hits.total.value: 3 }
89+
- length: { [email protected]: 3 }
90+
- match: { aggregations.d.count: 3 }
91+
- match: { aggregations.d.min: 1 }
92+
- match: { aggregations.d.max: 2 }
93+
- close_to: { aggregations.d.avg: {value: 1.333, error: 0.0005 }}
94+
- match: { aggregations.d.sum: 4.0 }
95+
- match: { aggregations.d.sum_of_squares: 6.0 }
96+
- close_to: { aggregations.d.variance: {value: 0.222, error: 0.0005 }}
97+
- close_to: { aggregations.d.variance_population: {value: 0.222, error: 0.0005 }}
98+
- close_to: { aggregations.d.variance_sampling: {value: 0.333, error: 0.0005 }}
99+
- close_to: { aggregations.d.std_deviation: {value: 0.471, error: 0.0005 }}
100+
- close_to: { aggregations.d.std_deviation_population: {value: 0.471, error: 0.0005 }}
101+
- close_to: { aggregations.d.std_deviation_sampling: {value: 0.577, error: 0.0005 }}
102+
- close_to: { aggregations.d.std_deviation_bounds.upper: {value: 2.276, error: 0.0005 }}
103+
- close_to: { aggregations.d.std_deviation_bounds.lower: {value: 0.391, error: 0.0005 }}
104+
- close_to: { aggregations.d.std_deviation_bounds.upper_population: {value: 2.276, error: 0.0005 }}
105+
- close_to: { aggregations.d.std_deviation_bounds.lower_population: {value: 0.391, error: 0.0005 }}
106+
- close_to: { aggregations.d.std_deviation_bounds.upper_sampling: {value: 2.488, error: 0.0005 }}
107+
- close_to: { aggregations.d.std_deviation_bounds.lower_sampling: {value: 0.179, error: 0.0005 }}
108+
- match: { aggregations.d.min_as_string: "1.00" }
109+
- match: { aggregations.d.max_as_string: "2.00" }
110+
- match: { aggregations.d.avg_as_string: "1.33" }
111+
- match: { aggregations.d.sum_as_string: "4.00" }
112+
- match: { aggregations.d.sum_of_squares_as_string: "6.00" }
113+
- match: { aggregations.d.variance_as_string: "0.22" }
114+
- match: { aggregations.d.variance_population_as_string: "0.22" }
115+
- match: { aggregations.d.variance_sampling_as_string: "0.33" }
116+
- match: { aggregations.d.std_deviation_as_string: "0.47" }
117+
- match: { aggregations.d.std_deviation_population_as_string: "0.47" }
118+
- match: { aggregations.d.std_deviation_sampling_as_string: "0.58" }
119+
- match: { aggregations.d.std_deviation_bounds_as_string.upper: "2.28" }
120+
- match: { aggregations.d.std_deviation_bounds_as_string.lower: "0.39" }
121+
- match: { aggregations.d.std_deviation_bounds_as_string.upper_population: "2.28" }
122+
- match: { aggregations.d.std_deviation_bounds_as_string.lower_population: "0.39" }
123+
- match: { aggregations.d.std_deviation_bounds_as_string.upper_sampling: "2.49" }
124+
- match: { aggregations.d.std_deviation_bounds_as_string.lower_sampling: "0.18" }
125+
126+
---
127+
gap_policy=skip:
128+
- skip:
129+
features: close_to
130+
131+
- do:
132+
search:
133+
index: gaps
134+
body:
135+
size: 0
136+
aggs:
137+
"@timestamp":
138+
date_histogram:
139+
field: "@timestamp"
140+
fixed_interval: 1h
141+
aggs:
142+
v: {avg: {field: v}}
143+
d:
144+
extended_stats_bucket:
145+
buckets_path: "@timestamp>v"
146+
gap_policy: skip
147+
- match: { hits.total.value: 3 }
148+
- length: { [email protected]: 4 }
149+
- match: { aggregations.d.count: 3 }
150+
- match: { aggregations.d.min: 1 }
151+
- match: { aggregations.d.max: 2 }
152+
- close_to: { aggregations.d.avg: {value: 1.333, error: 0.0005 }}
153+
- match: { aggregations.d.sum: 4.0 }
154+
- match: { aggregations.d.sum_of_squares: 6.0 }
155+
- close_to: { aggregations.d.variance: {value: 0.222, error: 0.0005 }}
156+
- close_to: { aggregations.d.variance_population: {value: 0.222, error: 0.0005 }}
157+
- close_to: { aggregations.d.variance_sampling: {value: 0.333, error: 0.0005 }}
158+
- close_to: { aggregations.d.std_deviation: {value: 0.471, error: 0.0005 }}
159+
- close_to: { aggregations.d.std_deviation_population: {value: 0.471, error: 0.0005 }}
160+
- close_to: { aggregations.d.std_deviation_sampling: {value: 0.577, error: 0.0005 }}
161+
- close_to: { aggregations.d.std_deviation_bounds.upper: {value: 2.276, error: 0.0005 }}
162+
- close_to: { aggregations.d.std_deviation_bounds.lower: {value: 0.391, error: 0.0005 }}
163+
- close_to: { aggregations.d.std_deviation_bounds.upper_population: {value: 2.276, error: 0.0005 }}
164+
- close_to: { aggregations.d.std_deviation_bounds.lower_population: {value: 0.391, error: 0.0005 }}
165+
- close_to: { aggregations.d.std_deviation_bounds.upper_sampling: {value: 2.488, error: 0.0005 }}
166+
- close_to: { aggregations.d.std_deviation_bounds.lower_sampling: {value: 0.179, error: 0.0005 }}
167+
168+
---
169+
gap_policy=insert_zeros:
170+
- skip:
171+
features: close_to
172+
173+
- do:
174+
search:
175+
index: gaps
176+
body:
177+
size: 0
178+
aggs:
179+
"@timestamp":
180+
date_histogram:
181+
field: "@timestamp"
182+
fixed_interval: 1h
183+
aggs:
184+
v: {avg: {field: v}}
185+
d:
186+
extended_stats_bucket:
187+
buckets_path: "@timestamp>v"
188+
gap_policy: insert_zeros
189+
- match: { hits.total.value: 3 }
190+
- length: { [email protected]: 4 }
191+
- match: { aggregations.d.count: 4 }
192+
- match: { aggregations.d.min: 0 }
193+
- match: { aggregations.d.max: 2 }
194+
- match: { aggregations.d.avg: 1 }
195+
- match: { aggregations.d.sum: 4.0 }
196+
- match: { aggregations.d.sum_of_squares: 6.0 }
197+
- close_to: { aggregations.d.variance: {value: 0.500, error: 0.0005 }}
198+
- close_to: { aggregations.d.variance_population: {value: 0.500, error: 0.0005 }}
199+
- close_to: { aggregations.d.variance_sampling: {value: 0.667, error: 0.0005 }}
200+
- close_to: { aggregations.d.std_deviation: {value: 0.707, error: 0.0005 }}
201+
- close_to: { aggregations.d.std_deviation_population: {value: 0.707, error: 0.0005 }}
202+
- close_to: { aggregations.d.std_deviation_sampling: {value: 0.816, error: 0.0005 }}
203+
- close_to: { aggregations.d.std_deviation_bounds.upper: {value: 2.414, error: 0.0005 }}
204+
- close_to: { aggregations.d.std_deviation_bounds.lower: {value: -0.414, error: 0.0005 }}
205+
- close_to: { aggregations.d.std_deviation_bounds.upper_population: {value: 2.414, error: 0.0005 }}
206+
- close_to: { aggregations.d.std_deviation_bounds.lower_population: {value: -0.414, error: 0.0005 }}
207+
- close_to: { aggregations.d.std_deviation_bounds.upper_sampling: {value: 2.633, error: 0.0005 }}
208+
- close_to: { aggregations.d.std_deviation_bounds.lower_sampling: {value: -0.633, error: 0.0005 }}
209+
210+
---
211+
gap_policy=keep_value:
212+
- skip:
213+
features: close_to
214+
215+
- do:
216+
search:
217+
index: gaps
218+
body:
219+
size: 0
220+
aggs:
221+
"@timestamp":
222+
date_histogram:
223+
field: "@timestamp"
224+
fixed_interval: 1h
225+
aggs:
226+
v: {avg: {field: v}}
227+
d:
228+
extended_stats_bucket:
229+
buckets_path: "@timestamp>v"
230+
gap_policy: keep_values
231+
- match: { hits.total.value: 3 }
232+
- length: { [email protected]: 4 }
233+
- match: { aggregations.d.count: 3 }
234+
- match: { aggregations.d.min: 1 }
235+
- match: { aggregations.d.max: 2 }
236+
- close_to: { aggregations.d.avg: {value: 1.333, error: 0.0005 }}
237+
- match: { aggregations.d.sum: 4.0 }
238+
- match: { aggregations.d.sum_of_squares: 6.0 }
239+
- close_to: { aggregations.d.variance: {value: 0.222, error: 0.0005 }}
240+
- close_to: { aggregations.d.variance_population: {value: 0.222, error: 0.0005 }}
241+
- close_to: { aggregations.d.variance_sampling: {value: 0.333, error: 0.0005 }}
242+
- close_to: { aggregations.d.std_deviation: {value: 0.471, error: 0.0005 }}
243+
- close_to: { aggregations.d.std_deviation_population: {value: 0.471, error: 0.0005 }}
244+
- close_to: { aggregations.d.std_deviation_sampling: {value: 0.577, error: 0.0005 }}
245+
- close_to: { aggregations.d.std_deviation_bounds.upper: {value: 2.276, error: 0.0005 }}
246+
- close_to: { aggregations.d.std_deviation_bounds.lower: {value: 0.391, error: 0.0005 }}
247+
- close_to: { aggregations.d.std_deviation_bounds.upper_population: {value: 2.276, error: 0.0005 }}
248+
- close_to: { aggregations.d.std_deviation_bounds.lower_population: {value: 0.391, error: 0.0005 }}
249+
- close_to: { aggregations.d.std_deviation_bounds.upper_sampling: {value: 2.488, error: 0.0005 }}
250+
- close_to: { aggregations.d.std_deviation_bounds.lower_sampling: {value: 0.179, error: 0.0005 }}

0 commit comments

Comments
 (0)