# How to disable or enable a document when do knn search

**URL:** <https://discuss.elastic.co/t/how-to-disable-or-enable-a-document-when-do-knn-search/351677>\
**Category:** Elasticsearch\
**Tags:** vector-search\
**Created:** [January 24, 2024, 2:08am UTC](https://discuss.elastic.co/t/how-to-disable-or-enable-a-document-when-do-knn-search/351677 "2024-01-24T02:08:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![r1ckC139](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/r1ckc139/32/117644_2.png) [@r1ckC139](https://discuss.elastic.co/u/r1ckC139)\
**Post date:** [January 24, 2024, 2:08am UTC](https://discuss.elastic.co/t/how-to-disable-or-enable-a-document-when-do-knn-search/351677/1 "2024-01-24T02:08:28Z")

</div>

Hello, in my index, there are certain documents that I want to disable or hide during a k-nearest neighbors (KNN) search. However, there may be situations where I need to enable or reveal these documents. How can I do this?

---

<div class="post-metadata">

**Author:** ![Priscilla\_Parodi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/priscilla_parodi/32/43047_2.png) [@Priscilla\_Parodi](https://discuss.elastic.co/u/Priscilla_Parodi)\
**Post date:** [January 24, 2024, 2:59am UTC](https://discuss.elastic.co/t/how-to-disable-or-enable-a-document-when-do-knn-search/351677/2 "2024-01-24T02:59:25Z")

</div>

Hello @r1ckC139,

When talking about disabling some documents, are you referring to restricting the search? If so, you can consider performing a [filtered kNN](https://www.elastic.co/guide/en/elasticsearch/reference/current/knn-search.html#knn-search-filter-example) search. The search will return the top k documents that also match the filter query. In situations that you don’t need it you would simply not perform a filtered search.

---

<div class="post-metadata">

**Author:** ![r1ckC139](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/r1ckc139/32/117644_2.png) [@r1ckC139](https://discuss.elastic.co/u/r1ckC139)\
**Post date:** [January 29, 2024, 4:14am UTC](https://discuss.elastic.co/t/how-to-disable-or-enable-a-document-when-do-knn-search/351677/3 "2024-01-29T04:14:42Z")

</div>

Hi there, if i have some documents are not ready to search (no vector-embedding field yet), how can i ignore these documents ?

---

<div class="post-metadata">

**Author:** ![yago82](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yago82/32/97755_2.png) [@yago82](https://discuss.elastic.co/u/yago82)\
**Post date:** [January 29, 2024, 4:33pm UTC](https://discuss.elastic.co/t/how-to-disable-or-enable-a-document-when-do-knn-search/351677/4 "2024-01-29T16:33:53Z")

</div>

> [@r1ckC139](#):
>
> Hello, in my index, there are certain documents that I want to disable or hide during a k-nearest neighbors (KNN) search. However, there may be situations where I need to enable or reveal these documents. How can I do this?

Hi,

you can use a filtered search to ignore these documents.

You can add a filter to your k-nearest neighbors (KNN) search query to only include documents where the vector-embedding field exists.

Regards

---

<div class="post-metadata">

**Author:** ![r1ckC139](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/r1ckc139/32/117644_2.png) [@r1ckC139](https://discuss.elastic.co/u/r1ckC139)\
**Post date:** [January 31, 2024, 2:19am UTC](https://discuss.elastic.co/t/how-to-disable-or-enable-a-document-when-do-knn-search/351677/5 "2024-01-31T02:19:04Z")

</div>

Hi  
I have tried and found that, documents without embedding fields will be automatically ignored by Elasticsearch.

---

<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:** [February 28, 2024, 2:19am UTC](https://discuss.elastic.co/t/how-to-disable-or-enable-a-document-when-do-knn-search/351677/6 "2024-02-28T02:19:57Z")

</div>

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