Skip to content

Commit ee1b87b

Browse files
authored
REST tests for top_hits (#83690) (#84441)
This adds a pile of extra REST tests for the `top_hits` aggregation which is useful because this is how we do mixed version cluster testing. And backwards compatibility testing. And forwards compatibility testing.
1 parent 2c1b34b commit ee1b87b

File tree

2 files changed

+347
-0
lines changed

2 files changed

+347
-0
lines changed
Lines changed: 347 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,347 @@
1+
setup:
2+
- do:
3+
indices.create:
4+
index: test
5+
body:
6+
settings:
7+
number_of_shards: 1
8+
mappings:
9+
properties:
10+
page:
11+
type: integer
12+
text:
13+
type: text
14+
store: true
15+
16+
- do:
17+
bulk:
18+
index: test
19+
refresh: true
20+
body:
21+
- '{ "index": {} }'
22+
- '{ "page": 1, "text": "the quick brown fox" }'
23+
- '{ "index": {} }'
24+
- '{ "page": 1, "text": "jumped over the lazy dog" }'
25+
- '{ "index": {} }'
26+
- '{ "page": 2, "text": "The vorpal blade went snicker-snack!" }'
27+
28+
---
29+
highlight:
30+
- do:
31+
search:
32+
index: test
33+
body:
34+
query:
35+
match:
36+
text: the
37+
aggs:
38+
page:
39+
terms:
40+
field: page
41+
aggs:
42+
top_hits:
43+
top_hits:
44+
highlight:
45+
fields:
46+
text: {}
47+
48+
- match: { hits.total.value: 3 }
49+
- length: { aggregations.page.buckets: 2 }
50+
- match: { aggregations.page.buckets.0.key: 1 }
51+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.0.highlight.text.0: "<em>the</em> quick brown fox" }
52+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.1.highlight.text.0: "jumped over <em>the</em> lazy dog" }
53+
- match: { aggregations.page.buckets.1.key: 2 }
54+
- match: { aggregations.page.buckets.1.top_hits.hits.hits.0.highlight.text.0: "<em>The</em> vorpal blade went snicker-snack!" }
55+
56+
---
57+
highlight_query:
58+
- do:
59+
search:
60+
index: test
61+
body:
62+
query:
63+
match:
64+
text: the
65+
aggs:
66+
page:
67+
terms:
68+
field: page
69+
aggs:
70+
top_hits:
71+
top_hits:
72+
highlight:
73+
fields:
74+
text:
75+
highlight_query:
76+
match:
77+
text: snack
78+
79+
- match: { hits.total.value: 3 }
80+
- length: { aggregations.page.buckets: 2 }
81+
- match: { aggregations.page.buckets.0.key: 1 }
82+
- is_false: aggregations.page.buckets.0.top_hits.hits.hits.0.highlight.text.0
83+
- is_false: aggregations.page.buckets.0.top_hits.hits.hits.1.highlight.text.0
84+
- match: { aggregations.page.buckets.1.key: 2 }
85+
- match: { aggregations.page.buckets.1.top_hits.hits.hits.0.highlight.text.0: "The vorpal blade went snicker-<em>snack</em>!" }
86+
87+
---
88+
explain:
89+
- skip:
90+
features: close_to
91+
92+
- do:
93+
search:
94+
index: test
95+
body:
96+
query:
97+
match:
98+
text: the
99+
aggs:
100+
page:
101+
terms:
102+
field: page
103+
aggs:
104+
top_hits:
105+
top_hits:
106+
explain: true
107+
108+
- match: { hits.total.value: 3 }
109+
- length: { aggregations.page.buckets: 2 }
110+
- match: { aggregations.page.buckets.0.key: 1 }
111+
- close_to: { aggregations.page.buckets.0.top_hits.hits.hits.0._explanation.value: { value: 0.14543022, error: 0.001 }}
112+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.0._explanation.description: "weight(text:the in 0) [PerFieldSimilarity], result of:" }
113+
- close_to: { aggregations.page.buckets.0.top_hits.hits.hits.1._explanation.value: { value: 0.13353139, error: 0.001 }}
114+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.1._explanation.description: "weight(text:the in 1) [PerFieldSimilarity], result of:" }
115+
- match: { aggregations.page.buckets.1.key: 2 }
116+
- close_to: { aggregations.page.buckets.1.top_hits.hits.hits.0._explanation.value: { value: 0.12343238, error: 0.001 }}
117+
- match: { aggregations.page.buckets.1.top_hits.hits.hits.0._explanation.description: "weight(text:the in 2) [PerFieldSimilarity], result of:" }
118+
119+
---
120+
from:
121+
- do:
122+
search:
123+
index: test
124+
body:
125+
query:
126+
match:
127+
text: the
128+
aggs:
129+
page:
130+
terms:
131+
field: page
132+
aggs:
133+
top_hits:
134+
top_hits:
135+
from: 1
136+
137+
- match: { hits.total.value: 3 }
138+
- length: { aggregations.page.buckets: 2 }
139+
- match: { aggregations.page.buckets.0.key: 1 }
140+
- length: { aggregations.page.buckets.0.top_hits.hits.hits: 1 }
141+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.0._source.text: "jumped over the lazy dog" }
142+
- match: { aggregations.page.buckets.1.key: 2 }
143+
- length: { aggregations.page.buckets.1.top_hits.hits.hits: 0 }
144+
145+
---
146+
size:
147+
- do:
148+
search:
149+
index: test
150+
body:
151+
query:
152+
match:
153+
text: the
154+
aggs:
155+
page:
156+
terms:
157+
field: page
158+
aggs:
159+
top_hits:
160+
top_hits:
161+
size: 1
162+
163+
- match: { hits.total.value: 3 }
164+
- length: { aggregations.page.buckets: 2 }
165+
- match: { aggregations.page.buckets.0.key: 1 }
166+
- length: { aggregations.page.buckets.0.top_hits.hits.hits: 1 }
167+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.0._source.text: "the quick brown fox" }
168+
- match: { aggregations.page.buckets.1.key: 2 }
169+
- length: { aggregations.page.buckets.1.top_hits.hits.hits: 1 }
170+
- match: { aggregations.page.buckets.1.top_hits.hits.hits.0._source.text: "The vorpal blade went snicker-snack!" }
171+
172+
---
173+
named queries:
174+
- do:
175+
search:
176+
index: test
177+
body:
178+
query:
179+
bool:
180+
should:
181+
- match:
182+
text:
183+
query: the
184+
_name: the
185+
- match:
186+
text:
187+
query: snack
188+
_name: snack
189+
aggs:
190+
page:
191+
terms:
192+
field: page
193+
aggs:
194+
top_hits:
195+
top_hits: {}
196+
197+
- match: { hits.total.value: 3 }
198+
- length: { aggregations.page.buckets: 2 }
199+
- match: { aggregations.page.buckets.0.key: 1 }
200+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.0.matched_queries: [the] }
201+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.1.matched_queries: [the] }
202+
- match: { aggregations.page.buckets.1.key: 2 }
203+
- match: { aggregations.page.buckets.1.top_hits.hits.hits.0.matched_queries: [the, snack] }
204+
205+
---
206+
fetch fields:
207+
- do:
208+
search:
209+
index: test
210+
body:
211+
fields: [text, page]
212+
aggs:
213+
page:
214+
terms:
215+
field: page
216+
aggs:
217+
top_hits:
218+
top_hits: {}
219+
220+
- match: { hits.total.value: 3 }
221+
- length: { aggregations.page.buckets: 2 }
222+
- match: { aggregations.page.buckets.0.key: 1 }
223+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.0.fields.text: [the quick brown fox] }
224+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.0.fields.page: [1] }
225+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.1.fields.text: [jumped over the lazy dog] }
226+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.1.fields.page: [1] }
227+
- match: { aggregations.page.buckets.1.key: 2 }
228+
- match: { aggregations.page.buckets.1.top_hits.hits.hits.0.fields.text: [The vorpal blade went snicker-snack!] }
229+
- match: { aggregations.page.buckets.1.top_hits.hits.hits.0.fields.page: [2] }
230+
231+
---
232+
source filtering:
233+
- do:
234+
search:
235+
index: test
236+
body:
237+
aggs:
238+
page:
239+
terms:
240+
field: page
241+
aggs:
242+
top_hits:
243+
top_hits:
244+
_source: text
245+
246+
- match: { hits.total.value: 3 }
247+
- length: { aggregations.page.buckets: 2 }
248+
- match: { aggregations.page.buckets.0.key: 1 }
249+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.0._source: {"text": "the quick brown fox" }}
250+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.1._source: {"text": "jumped over the lazy dog" }}
251+
- match: { aggregations.page.buckets.1.key: 2 }
252+
- match: { aggregations.page.buckets.1.top_hits.hits.hits.0._source: {"text": "The vorpal blade went snicker-snack!" }}
253+
254+
---
255+
stored fields:
256+
- do:
257+
search:
258+
index: test
259+
body:
260+
aggs:
261+
page:
262+
terms:
263+
field: page
264+
aggs:
265+
top_hits:
266+
top_hits:
267+
stored_fields: text
268+
269+
- match: { hits.total.value: 3 }
270+
- length: { aggregations.page.buckets: 2 }
271+
- match: { aggregations.page.buckets.0.key: 1 }
272+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.0.fields.text: [the quick brown fox] }
273+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.1.fields.text: [jumped over the lazy dog] }
274+
- match: { aggregations.page.buckets.1.key: 2 }
275+
- match: { aggregations.page.buckets.1.top_hits.hits.hits.0.fields.text: [The vorpal blade went snicker-snack!] }
276+
277+
---
278+
docvalue fields:
279+
- do:
280+
search:
281+
index: test
282+
body:
283+
aggs:
284+
page:
285+
terms:
286+
field: page
287+
aggs:
288+
top_hits:
289+
top_hits:
290+
docvalue_fields: [page]
291+
292+
- match: { hits.total.value: 3 }
293+
- length: { aggregations.page.buckets: 2 }
294+
- match: { aggregations.page.buckets.0.key: 1 }
295+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.0.fields.page: [1] }
296+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.1.fields.page: [1] }
297+
- match: { aggregations.page.buckets.1.key: 2 }
298+
- match: { aggregations.page.buckets.1.top_hits.hits.hits.0.fields.page: [2] }
299+
300+
---
301+
version:
302+
- do:
303+
search:
304+
index: test
305+
body:
306+
aggs:
307+
page:
308+
terms:
309+
field: page
310+
aggs:
311+
top_hits:
312+
top_hits:
313+
version: true
314+
315+
- match: { hits.total.value: 3 }
316+
- length: { aggregations.page.buckets: 2 }
317+
- match: { aggregations.page.buckets.0.key: 1 }
318+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.0._version: 1 }
319+
- match: { aggregations.page.buckets.0.top_hits.hits.hits.1._version: 1 }
320+
- match: { aggregations.page.buckets.1.key: 2 }
321+
- match: { aggregations.page.buckets.1.top_hits.hits.hits.0._version: 1 }
322+
323+
---
324+
sequence number and primary term:
325+
- do:
326+
search:
327+
index: test
328+
body:
329+
aggs:
330+
page:
331+
terms:
332+
field: page
333+
aggs:
334+
top_hits:
335+
top_hits:
336+
seq_no_primary_term: true
337+
338+
- match: { hits.total.value: 3 }
339+
- length: { aggregations.page.buckets: 2 }
340+
- match: { aggregations.page.buckets.0.key: 1 }
341+
- gte: { aggregations.page.buckets.0.top_hits.hits.hits.0._seq_no: 0 }
342+
- gte: { aggregations.page.buckets.0.top_hits.hits.hits.0._primary_term: 0 }
343+
- gte: { aggregations.page.buckets.0.top_hits.hits.hits.1._seq_no: 0 }
344+
- gte: { aggregations.page.buckets.0.top_hits.hits.hits.1._primary_term: 0 }
345+
- match: { aggregations.page.buckets.1.key: 2 }
346+
- gte: { aggregations.page.buckets.1.top_hits.hits.hits.0._seq_no: 0 }
347+
- gte: { aggregations.page.buckets.1.top_hits.hits.hits.0._primary_term: 0 }

0 commit comments

Comments
 (0)