From 1d7e2586f42be72932bbba63a2d09b826f1c7f05 Mon Sep 17 00:00:00 2001 From: Mike Pellegrini Date: Thu, 31 Jul 2025 11:38:21 -0400 Subject: [PATCH 1/2] Added YAML tests --- .../70_semantic_text_exists_query.yml | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/70_semantic_text_exists_query.yml b/x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/70_semantic_text_exists_query.yml index 11bd1f87aab06..6df527c5268a4 100644 --- a/x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/70_semantic_text_exists_query.yml +++ b/x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/70_semantic_text_exists_query.yml @@ -44,6 +44,8 @@ setup: inference_field: type: semantic_text inference_id: sparse-inference-id + text_field: + type: text - do: indices.create: @@ -54,6 +56,8 @@ setup: inference_field: type: semantic_text inference_id: dense-inference-id + text_field: + type: text --- "Exists query with no indexed documents": @@ -142,3 +146,59 @@ setup: field: "inference_field" - match: { hits.total.value: 1 } + +--- +"Exists query with indexed documents when semantic text field doesn't have a value": + - do: + index: + index: test-sparse-index + id: doc1 + body: + text_field: "foo" + refresh: true + + - do: + index: + index: test-sparse-index + id: doc2 + body: + inference_field: "bar" + refresh: true + + - do: + search: + index: test-sparse-index + body: + query: + exists: + field: "inference_field" + + - match: { hits.total.value: 1 } + - match: { hits.hits.0._id: "doc2" } + + - do: + index: + index: test-dense-index + id: doc1 + body: + text_field: "foo" + refresh: true + + - do: + index: + index: test-dense-index + id: doc2 + body: + inference_field: "bar" + refresh: true + + - do: + search: + index: test-dense-index + body: + query: + exists: + field: "inference_field" + + - match: { hits.total.value: 1 } + - match: { hits.hits.0._id: "doc2" } From c91fe93e15ffcf081a72524b1497b74ab559dfca Mon Sep 17 00:00:00 2001 From: Mike Pellegrini Date: Thu, 31 Jul 2025 12:18:06 -0400 Subject: [PATCH 2/2] Added another YAML test --- .../70_semantic_text_exists_query.yml | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/70_semantic_text_exists_query.yml b/x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/70_semantic_text_exists_query.yml index 6df527c5268a4..dcc3aee720808 100644 --- a/x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/70_semantic_text_exists_query.yml +++ b/x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/70_semantic_text_exists_query.yml @@ -202,3 +202,109 @@ setup: - match: { hits.total.value: 1 } - match: { hits.hits.0._id: "doc2" } + +--- +"Exists query with indexed documents with copy_to": + - do: + indices.create: + index: test-sparse-index-with-copy-to + body: + mappings: + properties: + inference_field: + type: semantic_text + inference_id: sparse-inference-id + source_field: + type: text + copy_to: inference_field + text_field: + type: text + + - do: + index: + index: test-sparse-index-with-copy-to + id: doc1 + body: + text_field: "foo" + refresh: true + + - do: + search: + index: test-sparse-index-with-copy-to + body: + query: + exists: + field: "inference_field" + + - match: { hits.total.value: 0 } + + - do: + index: + index: test-sparse-index-with-copy-to + id: doc2 + body: + source_field: "bar" + refresh: true + + - do: + search: + index: test-sparse-index-with-copy-to + body: + query: + exists: + field: "inference_field" + + - match: { hits.total.value: 1 } + - match: { hits.hits.0._id: "doc2" } + + - do: + indices.create: + index: test-dense-index-with-copy-to + body: + mappings: + properties: + inference_field: + type: semantic_text + inference_id: dense-inference-id + source_field: + type: text + copy_to: inference_field + text_field: + type: text + + - do: + index: + index: test-dense-index-with-copy-to + id: doc1 + body: + text_field: "foo" + refresh: true + + - do: + search: + index: test-dense-index-with-copy-to + body: + query: + exists: + field: "inference_field" + + - match: { hits.total.value: 0 } + + - do: + index: + index: test-dense-index-with-copy-to + id: doc2 + body: + source_field: "bar" + refresh: true + + - do: + search: + index: test-dense-index-with-copy-to + body: + query: + exists: + field: "inference_field" + + - match: { hits.total.value: 1 } + - match: { hits.hits.0._id: "doc2" }