Skip to content

Commit 59d0842

Browse files
committed
Add YAML REST tests for filters bucket agg
Related to #26220
1 parent f37eb1b commit 59d0842

File tree

1 file changed

+259
-0
lines changed

1 file changed

+259
-0
lines changed
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
setup:
2+
- do:
3+
indices.create:
4+
index: test_1
5+
body:
6+
settings:
7+
number_of_replicas: 0
8+
mappings:
9+
doc:
10+
properties:
11+
int_field:
12+
type : integer
13+
double_field:
14+
type : double
15+
string_field:
16+
type: keyword
17+
18+
- do:
19+
bulk:
20+
refresh: true
21+
body:
22+
- index:
23+
_index: test_1
24+
_type: doc
25+
_id: 1
26+
- int_field: 1
27+
double_field: 1.0
28+
string_field: foo
29+
- index:
30+
_index: test_1
31+
_type: doc
32+
_id: 2
33+
- int_field: 51
34+
double_field: 51.0
35+
string_field: foo
36+
- index:
37+
_index: test_1
38+
_type: doc
39+
_id: 3
40+
- int_field: 101
41+
double_field: 101.0
42+
string_field: foo
43+
- index:
44+
_index: test_1
45+
_type: doc
46+
_id: 4
47+
- int_field: 151
48+
double_field: 151.0
49+
string_field: foo
50+
51+
---
52+
"Basic test":
53+
54+
- do:
55+
search:
56+
body:
57+
aggs:
58+
the_filter:
59+
filters:
60+
filters:
61+
first_filter:
62+
match:
63+
int_field: 101
64+
second_filter:
65+
match:
66+
int_field: 151
67+
68+
- match: { hits.total: 4 }
69+
- length: { hits.hits: 4 }
70+
- match: { aggregations.the_filter.buckets.first_filter.doc_count: 1 }
71+
- match: { aggregations.the_filter.buckets.second_filter.doc_count: 1 }
72+
73+
- do:
74+
search:
75+
body:
76+
aggs:
77+
the_filter:
78+
filters:
79+
filters:
80+
first_filter:
81+
match:
82+
int_field: 101
83+
second_filter:
84+
match:
85+
int_field: 151
86+
aggs:
87+
the_avg:
88+
avg:
89+
field: int_field
90+
91+
- match: { hits.total: 4 }
92+
- length: { hits.hits: 4 }
93+
- match: { aggregations.the_filter.buckets.first_filter.doc_count: 1 }
94+
- match: { aggregations.the_filter.buckets.first_filter.the_avg.value: 101.0 }
95+
- match: { aggregations.the_filter.buckets.second_filter.doc_count: 1 }
96+
- match: { aggregations.the_filter.buckets.second_filter.the_avg.value: 151.0 }
97+
98+
---
99+
"Anonymous filters test":
100+
101+
- do:
102+
search:
103+
body:
104+
aggs:
105+
the_filter:
106+
filters:
107+
filters:
108+
- match:
109+
int_field: 101
110+
- match:
111+
int_field: 151
112+
113+
- match: { hits.total: 4 }
114+
- length: { hits.hits: 4 }
115+
- match: { aggregations.the_filter.buckets.0.doc_count: 1 }
116+
- match: { aggregations.the_filter.buckets.1.doc_count: 1 }
117+
118+
- do:
119+
search:
120+
body:
121+
aggs:
122+
the_filter:
123+
filters:
124+
filters:
125+
- match:
126+
int_field: 101
127+
- match:
128+
int_field: 151
129+
aggs:
130+
the_avg:
131+
avg:
132+
field: int_field
133+
134+
- match: { hits.total: 4 }
135+
- length: { hits.hits: 4 }
136+
- match: { aggregations.the_filter.buckets.0.doc_count: 1 }
137+
- match: { aggregations.the_filter.buckets.0.the_avg.value: 101.0 }
138+
- match: { aggregations.the_filter.buckets.1.doc_count: 1 }
139+
- match: { aggregations.the_filter.buckets.1.the_avg.value: 151.0 }
140+
141+
---
142+
"Only aggs test":
143+
144+
- do:
145+
search:
146+
body:
147+
size: 0
148+
aggs:
149+
the_filter:
150+
filters:
151+
filters:
152+
first_filter:
153+
match:
154+
int_field: 101
155+
second_filter:
156+
match:
157+
int_field: 151
158+
159+
- match: { hits.total: 4 }
160+
- length: { hits.hits: 0 }
161+
- match: { aggregations.the_filter.buckets.first_filter.doc_count: 1 }
162+
- match: { aggregations.the_filter.buckets.second_filter.doc_count: 1 }
163+
164+
- do:
165+
search:
166+
body:
167+
aggs:
168+
the_filter:
169+
filters:
170+
filters:
171+
first_filter:
172+
match:
173+
int_field: 101
174+
second_filter:
175+
match:
176+
int_field: 151
177+
aggs:
178+
the_avg:
179+
avg:
180+
field: int_field
181+
182+
- match: { hits.total: 4 }
183+
- length: { hits.hits: 4 }
184+
- match: { aggregations.the_filter.buckets.first_filter.doc_count: 1 }
185+
- match: { aggregations.the_filter.buckets.first_filter.the_avg.value: 101.0 }
186+
- match: { aggregations.the_filter.buckets.second_filter.doc_count: 1 }
187+
- match: { aggregations.the_filter.buckets.second_filter.the_avg.value: 151.0 }
188+
189+
---
190+
"Filtered test":
191+
192+
- do:
193+
search:
194+
body:
195+
query:
196+
constant_score:
197+
filter:
198+
range:
199+
int_field:
200+
gte: 110
201+
aggs:
202+
the_filter:
203+
filters:
204+
filters:
205+
first_filter:
206+
match:
207+
int_field: 101
208+
second_filter:
209+
match:
210+
int_field: 151
211+
aggs:
212+
the_avg:
213+
avg:
214+
field: int_field
215+
216+
- match: { hits.total: 1 }
217+
- length: { hits.hits: 1 }
218+
- match: { aggregations.the_filter.buckets.first_filter.doc_count: 0 }
219+
- is_false: aggregations.the_filter.buckets.first_filter.the_avg.value
220+
- match: { aggregations.the_filter.buckets.second_filter.doc_count: 1 }
221+
- match: { aggregations.the_filter.buckets.second_filter.the_avg.value: 151.0 }
222+
223+
224+
---
225+
"Metadata test":
226+
227+
- do:
228+
search:
229+
body:
230+
aggs:
231+
the_filter:
232+
meta:
233+
foo: bar
234+
filters:
235+
filters:
236+
first_filter:
237+
match:
238+
int_field: 101
239+
second_filter:
240+
match:
241+
int_field: 151
242+
243+
- match: { hits.total: 4 }
244+
- length: { hits.hits: 4 }
245+
- match: { aggregations.the_filter.buckets.first_filter.doc_count: 1 }
246+
- match: { aggregations.the_filter.buckets.second_filter.doc_count: 1 }
247+
- match: { aggregations.the_filter.meta.foo: "bar" }
248+
249+
---
250+
"Bad params":
251+
252+
- do:
253+
search:
254+
body:
255+
aggs:
256+
the_filter:
257+
filters:
258+
filters: []
259+

0 commit comments

Comments
 (0)