# Knn as percolator query

**URL:** https://discuss.elastic.co/t/knn-as-percolator-query/340066
**Category:** Elasticsearch
**Tags:** vector-search
**Created:** [August 3, 2023, 3:44pm UTC](https://discuss.elastic.co/t/knn-as-percolator-query/340066 "2023-08-03T15:44:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Matthew\_Pollard](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matthew_pollard/32/124298_2.png) [@Matthew\_Pollard](https://discuss.elastic.co/u/Matthew_Pollard)
#### Post date: [August 3, 2023, 3:44pm UTC](https://discuss.elastic.co/t/knn-as-percolator-query/340066/1 "2023-08-03T15:44:59Z")

</div>

Hi

Just wondering whether it is currently possible to use a knn query as a percolater query - my feeling is that this is currently not possible but just checking?

Thanks

Matthew

---

<div class="post-metadata">

### Author: ![BenTrent](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bentrent/32/33915_2.png) [@BenTrent](https://discuss.elastic.co/u/BenTrent)
#### Post date: [August 3, 2023, 4:37pm UTC](https://discuss.elastic.co/t/knn-as-percolator-query/340066/2 "2023-08-03T16:37:35Z")

</div>

@Matthew_Pollard ,

Not yet, but this is a nice idea.

We are currently thinking about how to expose `knn` as a query directly instead of always requiring the top level search element called `knn`.

> <https://github.com/elastic/elasticsearch/issues/97940>
>
> \### Description
> 
> Currently knn is a top section of a search request. knn searc…h runs in the DFS phase, which allows to collect global top k results regardless of a number of shards. This is very useful for aggregations, as only global top K results will be included in aggregations' results. 
> A limitation of having knn as a top section is that knn search by itself can not be combined or nested within other queries.
> 
> There are two ways to approach this:
> 1. Introduce a new query \`knn\_shard\` query that works on a shard level in the Query phase similar to all other queries.
> 2. Modify the current DSL to make \`knn\` as a query, but keep the internal implementation the same (i.e. internally knn search will still run during DFS phase and collect top global k).

If you have an opinion on rather you care for always GLOBAL top-k or top-k per shard, let us know 🙂

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [August 31, 2023, 4:38pm UTC](https://discuss.elastic.co/t/knn-as-percolator-query/340066/3 "2023-08-31T16:38:23Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
