# How to filter in multi knn query

**URL:** <https://discuss.elastic.co/t/how-to-filter-in-multi-knn-query/362582>\
**Category:** Elasticsearch\
**Tags:** vector-search\
**Created:** [July 4, 2024, 9:26pm UTC](https://discuss.elastic.co/t/how-to-filter-in-multi-knn-query/362582 "2024-07-04T21:26:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![melkon](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@melkon](https://discuss.elastic.co/u/melkon)\
**Post date:** [July 4, 2024, 9:26pm UTC](https://discuss.elastic.co/t/how-to-filter-in-multi-knn-query/362582/1 "2024-07-04T21:26:52Z")

</div>

Hi. I'm trying to use filter in multi knn query but getting below error.

It's working with the [example from docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/knn-search.html#knn-search-filter-example) but I need to apply pre filter for case when knn is array of many knn queries.

`Elasticsearch::Transport::Transport::Errors::InternalServerError: [500] {"error":{"root_cause":[{"type":"illegal_state_exception","reason":"Parent query must not match any docs besides parent filter. Combine them as must (+) and must-not (-) clauses to find a problem doc. docID=56378"}]`

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 5, 2024, 7:52am UTC](https://discuss.elastic.co/t/how-to-filter-in-multi-knn-query/362582/2 "2024-07-05T07:52:36Z")

</div>

Welcome!

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can **copy and paste in Kibana dev console** , click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

Have a look at the [Elastic Stack and Solutions Help · Forums and Slack | Elastic](https://elastic.co/community/help) page. It contains also lot of useful information on how to ask for help.
