Skip to content

Commit 4d73957

Browse files
committed
Document kNN with aggregations (#89359)
This commit adds a short note to the 'search your data' docs around kNN search to explain how approximate kNN works with aggregations: * Make section on 'hybrid retrieval' more general and include aggregations info * Remove an example response from the previous section on filtering, since this page was getting long
1 parent 3d712e3 commit 4d73957

File tree

1 file changed

+6
-34
lines changed

1 file changed

+6
-34
lines changed

docs/reference/search/search-your-data/knn-search.asciidoc

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -279,41 +279,8 @@ POST image-index/_search
279279
----
280280
// TEST[continued]
281281

282-
[source,console-result]
283-
----
284-
{
285-
"took": 5,
286-
"timed_out": false,
287-
"_shards": {
288-
"total": 1,
289-
"successful": 1,
290-
"skipped": 0,
291-
"failed": 0
292-
},
293-
"hits": {
294-
"total": {
295-
"value": 1,
296-
"relation": "eq"
297-
},
298-
"max_score": 0.003144654,
299-
"hits": [
300-
{
301-
"_index": "image-index",
302-
"_id": "2",
303-
"_score": 0.003144654,
304-
"fields": {
305-
"title": ["alpine lake"]
306-
}
307-
}
308-
]
309-
}
310-
}
311-
----
312-
// TESTRESPONSE[s/"took": 5/"took": $body.took/]
313-
// TESTRESPONSE[s/,\n \.\.\.//]
314-
315282
[discrete]
316-
==== Combine approximate kNN and a query
283+
==== Combine approximate kNN with other features
317284

318285
You can perform 'hybrid retrieval' by providing both the
319286
<<search-api-knn, `knn` option>> and a <<request-body-search-query, `query`>>:
@@ -354,6 +321,11 @@ each score in the sum. In the example above, the scores will be calculated as
354321
score = 0.9 * match_score + 0.1 * knn_score
355322
```
356323

324+
The `knn` option can also be used with <<search-aggregations, `aggregations`>>. In general, {es} computes aggregations
325+
over all documents that match the search. So for approximate kNN search, aggregations are calculated on the top `k`
326+
nearest documents. If the search also includes a `query`, then aggregations are calculated on the combined set of `knn`
327+
and `query` matches.
328+
357329
[discrete]
358330
[[knn-indexing-considerations]]
359331
==== Indexing considerations

0 commit comments

Comments
 (0)