Skip to content

Commit 685cb59

Browse files
authored
Improve Semantic Text Exists Query Tests (#132283) (#132329)
1 parent 727d5e7 commit 685cb59

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed

x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/70_semantic_text_exists_query.yml

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ setup:
4444
inference_field:
4545
type: semantic_text
4646
inference_id: sparse-inference-id
47+
text_field:
48+
type: text
4749

4850
- do:
4951
indices.create:
@@ -54,6 +56,8 @@ setup:
5456
inference_field:
5557
type: semantic_text
5658
inference_id: dense-inference-id
59+
text_field:
60+
type: text
5761

5862
---
5963
"Exists query with no indexed documents":
@@ -142,3 +146,165 @@ setup:
142146
field: "inference_field"
143147

144148
- match: { hits.total.value: 1 }
149+
150+
---
151+
"Exists query with indexed documents when semantic text field doesn't have a value":
152+
- do:
153+
index:
154+
index: test-sparse-index
155+
id: doc1
156+
body:
157+
text_field: "foo"
158+
refresh: true
159+
160+
- do:
161+
index:
162+
index: test-sparse-index
163+
id: doc2
164+
body:
165+
inference_field: "bar"
166+
refresh: true
167+
168+
- do:
169+
search:
170+
index: test-sparse-index
171+
body:
172+
query:
173+
exists:
174+
field: "inference_field"
175+
176+
- match: { hits.total.value: 1 }
177+
- match: { hits.hits.0._id: "doc2" }
178+
179+
- do:
180+
index:
181+
index: test-dense-index
182+
id: doc1
183+
body:
184+
text_field: "foo"
185+
refresh: true
186+
187+
- do:
188+
index:
189+
index: test-dense-index
190+
id: doc2
191+
body:
192+
inference_field: "bar"
193+
refresh: true
194+
195+
- do:
196+
search:
197+
index: test-dense-index
198+
body:
199+
query:
200+
exists:
201+
field: "inference_field"
202+
203+
- match: { hits.total.value: 1 }
204+
- match: { hits.hits.0._id: "doc2" }
205+
206+
---
207+
"Exists query with indexed documents with copy_to":
208+
- do:
209+
indices.create:
210+
index: test-sparse-index-with-copy-to
211+
body:
212+
mappings:
213+
properties:
214+
inference_field:
215+
type: semantic_text
216+
inference_id: sparse-inference-id
217+
source_field:
218+
type: text
219+
copy_to: inference_field
220+
text_field:
221+
type: text
222+
223+
- do:
224+
index:
225+
index: test-sparse-index-with-copy-to
226+
id: doc1
227+
body:
228+
text_field: "foo"
229+
refresh: true
230+
231+
- do:
232+
search:
233+
index: test-sparse-index-with-copy-to
234+
body:
235+
query:
236+
exists:
237+
field: "inference_field"
238+
239+
- match: { hits.total.value: 0 }
240+
241+
- do:
242+
index:
243+
index: test-sparse-index-with-copy-to
244+
id: doc2
245+
body:
246+
source_field: "bar"
247+
refresh: true
248+
249+
- do:
250+
search:
251+
index: test-sparse-index-with-copy-to
252+
body:
253+
query:
254+
exists:
255+
field: "inference_field"
256+
257+
- match: { hits.total.value: 1 }
258+
- match: { hits.hits.0._id: "doc2" }
259+
260+
- do:
261+
indices.create:
262+
index: test-dense-index-with-copy-to
263+
body:
264+
mappings:
265+
properties:
266+
inference_field:
267+
type: semantic_text
268+
inference_id: dense-inference-id
269+
source_field:
270+
type: text
271+
copy_to: inference_field
272+
text_field:
273+
type: text
274+
275+
- do:
276+
index:
277+
index: test-dense-index-with-copy-to
278+
id: doc1
279+
body:
280+
text_field: "foo"
281+
refresh: true
282+
283+
- do:
284+
search:
285+
index: test-dense-index-with-copy-to
286+
body:
287+
query:
288+
exists:
289+
field: "inference_field"
290+
291+
- match: { hits.total.value: 0 }
292+
293+
- do:
294+
index:
295+
index: test-dense-index-with-copy-to
296+
id: doc2
297+
body:
298+
source_field: "bar"
299+
refresh: true
300+
301+
- do:
302+
search:
303+
index: test-dense-index-with-copy-to
304+
body:
305+
query:
306+
exists:
307+
field: "inference_field"
308+
309+
- match: { hits.total.value: 1 }
310+
- match: { hits.hits.0._id: "doc2" }

0 commit comments

Comments
 (0)