-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Disallow kNN searches on nested vector fields #79403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,26 @@ setup: | |
dims: 5 | ||
index: true | ||
similarity: l2_norm | ||
comments: | ||
type: nested | ||
properties: | ||
body: | ||
type: text | ||
vector: | ||
type: dense_vector | ||
dims: 5 | ||
index: true | ||
similarity: l2_norm | ||
|
||
- do: | ||
index: | ||
index: test | ||
body: | ||
name: cow.jpg | ||
vector: [230.0, 300.33, -34.8988, 15.555, -200.0] | ||
comments: | ||
- body: "free the cows" | ||
vector: [0.75, 100.0, 0.33, 16.2, -10.2] | ||
|
||
- do: | ||
index: | ||
|
@@ -28,6 +42,9 @@ setup: | |
body: | ||
name: moose.jpg | ||
vector: [-0.5, 100.0, -13, 14.8, -156.0] | ||
comments: | ||
- body: "what a great moose" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cool descriptions!!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hehe, I got bored with my usual test examples :) |
||
vector: [11.4, 99.0, 1.55, -2.9, -10.2] | ||
|
||
- do: | ||
index: | ||
|
@@ -63,19 +80,20 @@ setup: | |
"Test nonexistent field": | ||
- do: | ||
catch: bad_request | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test-index | ||
knn_search: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are extra changes here because I caught and fixed some mistakes in these REST tests. |
||
index: test | ||
body: | ||
query: | ||
knn: | ||
field: nonexistent | ||
query_vector: [ -0.5, 90.0, -10, 14.8, -156.0 ] | ||
num_candidates: 1 | ||
- match: { error.root_cause.0.type: "illegal_argument_exception" } | ||
fields: [ "name" ] | ||
knn: | ||
field: nonexistent | ||
query_vector: [ -0.5, 90.0, -10, 14.8, -156.0 ] | ||
k: 2 | ||
num_candidates: 3 | ||
- match: { error.root_cause.0.type: "query_shard_exception" } | ||
- match: { error.root_cause.0.reason: "failed to create query: field [nonexistent] does not exist in the mapping" } | ||
|
||
--- | ||
"Direct knn queries are disallowed": | ||
"Direct kNN queries are disallowed": | ||
- do: | ||
catch: bad_request | ||
search: | ||
|
@@ -88,3 +106,20 @@ setup: | |
query_vector: [ -0.5, 90.0, -10, 14.8, -156.0 ] | ||
num_candidates: 1 | ||
- match: { error.root_cause.0.type: "illegal_argument_exception" } | ||
- match: { error.root_cause.0.reason: "[knn] queries cannot be provided directly, use the [_knn_search] endpoint instead" } | ||
|
||
--- | ||
"kNN searches on nested fields are disallowed": | ||
- do: | ||
catch: bad_request | ||
knn_search: | ||
index: test | ||
body: | ||
fields: [ "nonexistent" ] | ||
knn: | ||
field: comments.vector | ||
query_vector: [ -0.5, 90.0, -10, 14.8, -156.0 ] | ||
k: 2 | ||
num_candidates: 3 | ||
- match: { error.root_cause.0.type: "query_shard_exception" } | ||
- match: { error.root_cause.0.reason: "failed to create query: [knn] queries are not supported on nested fields" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems that the previous
getNestedParent
will returnnull
ifpath
is not an objectMapper? But from how this method was used, it looks like this check is not important. So this change LGTM.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, this behavior is different but I also couldn't find any place where this check was important.