-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Support kNN filter on nested metadata #113949
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 1 commit
d29e647
6e6abae
426db4d
d9eb1e9
891b091
923b6c0
d9a13a9
9aa706f
9c56fff
afe3d8f
7bc25d3
e3b0251
a2f365e
f423619
acbfccd
7cc0b09
1aa3605
5a818bc
6c3230e
c0bb4ff
24e4943
8f9cf54
867b928
cdf4e92
d6d5f8e
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 |
---|---|---|
|
@@ -25,6 +25,13 @@ setup: | |
dims: 5 | ||
index: true | ||
similarity: l2_norm | ||
nested2: | ||
type: nested | ||
properties: | ||
key: | ||
type: keyword | ||
value: | ||
type: keyword | ||
aliases: | ||
my_alias: | ||
filter: | ||
|
@@ -44,6 +51,11 @@ setup: | |
- paragraph_id: 1 | ||
vector: [240.0, 300, -3, 1, -20] | ||
language: FR | ||
nested2: | ||
- key: "category" | ||
value: "domestic" | ||
- key: "level" | ||
value: "beginner" | ||
|
||
- do: | ||
index: | ||
|
@@ -61,6 +73,12 @@ setup: | |
- paragraph_id: 3 | ||
vector: [0, 1.0, 0, 1.8, -15.0] | ||
language: FR | ||
nested2: | ||
- key: "category" | ||
value: "wild" | ||
- key: "level" | ||
value: "beginner" | ||
|
||
|
||
- do: | ||
index: | ||
|
@@ -72,6 +90,11 @@ setup: | |
- paragraph_id: 0 | ||
vector: [0.5, 111.3, -13.0, 14.8, -156.0] | ||
language: FR | ||
nested2: | ||
- key: "category" | ||
value: "domestic" | ||
- key: "level" | ||
value: "advanced" | ||
|
||
- do: | ||
indices.refresh: {} | ||
|
@@ -521,3 +544,42 @@ setup: | |
- match: { hits.hits.0.inner_hits.nested.hits.hits.0.fields.nested.0.language.0: "FR" } | ||
- close_to: { hits.hits.0._score: { value: 0.0041, error: 0.0001 } } | ||
- close_to: { hits.hits.0.inner_hits.nested.hits.hits.0._score: { value: 0.0041, error: 0.0001 } } | ||
|
||
|
||
--- | ||
"Test filter on sibling nested fields doesn't work": | ||
- requires: | ||
capabilities: | ||
- method: POST | ||
path: /_search | ||
capabilities: [ knn_filter_on_nested_fields ] | ||
test_runner_features: ["capabilities", "close_to"] | ||
reason: "Capability for filtering on nested fields required" | ||
|
||
- do: | ||
search: | ||
index: test | ||
body: | ||
_source: false | ||
query: | ||
nested: | ||
path: nested | ||
query: | ||
knn: | ||
field: nested.vector | ||
query_vector: [-0.5, 90.0, -10, 14.8, -156.0] | ||
k: 10 | ||
filter: | ||
nested: | ||
path: nested2 | ||
query: | ||
bool: | ||
filter: | ||
- match: | ||
nested2.key: "category" | ||
- match: | ||
nested2.value: "domestic" | ||
inner_hits: { size: 3, "fields": [ "nested.paragraph_id", "nested.language"], _source: false } | ||
|
||
- match: { hits.total.value: 0 } | ||
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. @benwtrent Notice how for nested query the DSL itself doesn't allow to filter on nested sibling fields, as the top level query:nested:path sets the parent context. 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. @mayya-sharipova thank you. I was thinking it would be possible via 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. They key issue is that with kNN search, we need to be clear that its within a SINGLE nested context (either top level, or its own context). That gets tricky, and maybe we can make it better in the future. But the current compromise unblocks some folks. 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. I can not think of any way to support pre-filtering on nested sibling fields in knn query. We can do the following, but it would be post-filter: - do:
search:
index: test
body:
_source: false
query:
bool:
must:
- nested:
path: nested
query:
knn:
field: nested.vector
query_vector: [-0.5, 90.0, -10, 14.8, -156.0]
k: 10
filter:
- nested:
path: nested2
query:
bool:
filter:
- match:
nested2.key: "category"
- match:
nested2.value: "domestic" |
||
|
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.
Here with the current implementation we can query nested sibling 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.
I was sort of hoping that we could do something similar in the nested query since we look to the parent level. But it gets too complicated given the nested context?