Skip to content

Commit

Permalink
Fixing exists query REST tests for sparse_vector_fields (#100030)
Browse files Browse the repository at this point in the history
Removing (incorrectly) expected exceptions for `exists` queries `sparse_vectors`  in  < 8.0.0 versions.

Closes #100003
  • Loading branch information
pmpailis authored Oct 6, 2023
1 parent 7012584 commit 24353a9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
"Indexing and searching sparse vectors":
"Indexing and searching sparse vectors in >=8.11":

- skip:
version: " - 8.10.99"
Expand Down Expand Up @@ -77,16 +77,24 @@
index: test
id: "3"
body:
text: "doing nothing will result in nothing"
text: "empty array with no nested values - should not be retrieved in exists queries"
ml:
tokens: {}
tokens: [ ]
- do:
index:
index: test
id: "4"
body:
text: "should still respond to exists queries if when empty"
ml:
tokens: { }

- match: { result: "created" }

- do:
index:
index: test
id: "4"
id: "5"
body:
text: "other embeddings available only"
embeddings:
Expand Down Expand Up @@ -144,9 +152,9 @@
---
"Sparse vector in 7.x":
- skip:
features: allowed_warnings
version: "all"
reason: "AwaitsFix https://github.com/elastic/elasticsearch/issues/100003"
features: ["allowed_warnings"]
version: "8.0.0 - "
reason: "sparse_vector field type supported in 7.x"
- do:
allowed_warnings:
- "The [sparse_vector] field type is deprecated and will be removed in 8.0."
Expand All @@ -164,17 +172,16 @@
- match: { acknowledged: true }

- do:
catch: /\[sparse_vector\] fields do not support \[exists\] queries/
allowed_warnings:
- "[sparse_vector] field type in old 7.x indices is allowed to contain [sparse_vector] fields, but they cannot be indexed or searched."
search:
rest_total_hits_as_int: true
index: test
body:
query:
exists:
field: ml.tokens

---
"Sparse vector in 8.x":
"Sparse vector in 8.0.0 <= x < 8.11.0":
- skip:
version: " - 7.99.99, 8.11.0 - "
reason: "sparse_vector field type not supported in 8.x until 8.11.0"
Expand All @@ -189,3 +196,12 @@
type: text
ml.tokens:
type: sparse_vector
- do:
catch: /\[sparse_vector\] fields do not support \[exists\] queries|no such index.*/
search:
rest_total_hits_as_int: true
index: test
body:
query:
exists:
field: ml.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.elasticsearch.index.mapper.vectors;

import org.apache.lucene.document.FeatureField;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.logging.DeprecationCategory;
Expand Down Expand Up @@ -110,8 +111,11 @@ public Query termQuery(Object value, SearchExecutionContext context) {

@Override
public Query existsQuery(SearchExecutionContext context) {
// No support for exists queries prior to this version
if (context.getIndexSettings().getIndexVersionCreated().before(SPARSE_VECTOR_IN_FIELD_NAMES_INDEX_VERSION)) {
if (context.getIndexSettings().getIndexVersionCreated().before(PREVIOUS_SPARSE_VECTOR_INDEX_VERSION)) {
deprecationLogger.warn(DeprecationCategory.MAPPINGS, "sparse_vector", ERROR_MESSAGE_7X);
return new MatchNoDocsQuery();
} else if (context.getIndexSettings().getIndexVersionCreated().before(SPARSE_VECTOR_IN_FIELD_NAMES_INDEX_VERSION)) {
// No support for exists queries prior to this version on 8.x
throw new IllegalArgumentException("[sparse_vector] fields do not support [exists] queries");
}
return super.existsQuery(context);
Expand Down

0 comments on commit 24353a9

Please sign in to comment.