You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/query-languages/query-dsl/query-dsl-knn-query.md
+51-8Lines changed: 51 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -203,10 +203,19 @@ POST my-image-index/_search
203
203
`knn` query can be used inside a nested query. The behaviour here is similar to [top level nested kNN search](docs-content://solutions/search/vector/knn.md#nested-knn-search):
204
204
205
205
* kNN search over nested dense_vectors diversifies the top results over the top-level document
206
-
*`filter` over the top-level document metadata is supported and acts as a pre-filter
207
-
*`filter` over `nested` field metadata is not supported
206
+
*`filter` both over the top-level document metadata and `nested` is supported and acts as a pre-filter
207
+
208
+
::::{note}
209
+
To ensure correct results: each individual filter must be either over
210
+
the top-level metadata or `nested` metadata. However, a single knn query
211
+
supports multiple filters, where some filters can be over the top-level
212
+
metadata and some over nested.
213
+
::::
208
214
209
-
A sample query can look like below:
215
+
216
+
Below is a sample query with filter over nested metadata.
217
+
For scoring parents' documents, this query only considers vectors that
218
+
have "paragraph.language" set to "EN".
210
219
211
220
```json
212
221
{
@@ -215,12 +224,46 @@ A sample query can look like below:
215
224
"path" : "paragraph",
216
225
"query" : {
217
226
"knn": {
218
-
"query_vector": [
219
-
0.45,
220
-
45
221
-
],
227
+
"query_vector": [0.45, 0.50],
222
228
"field": "paragraph.vector",
223
-
"num_candidates": 2
229
+
"filter": {
230
+
"match": {
231
+
"paragraph.language": "EN"
232
+
}
233
+
}
234
+
}
235
+
}
236
+
}
237
+
}
238
+
}
239
+
```
240
+
241
+
Below is a sample query with two filters: one over nested metadata
242
+
and another over the top level metadata. For scoring parents' documents,
243
+
this query only considers vectors whose parent's title contain "essay"
0 commit comments