# Include & Exclude of 500k ids in a search query

**URL:** <https://discuss.elastic.co/t/include-exclude-of-500k-ids-in-a-search-query/296428>\
**Category:** Elasticsearch\
**Created:** [February 7, 2022, 7:26am UTC](https://discuss.elastic.co/t/include-exclude-of-500k-ids-in-a-search-query/296428 "2022-02-07T07:26:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanders\_2345](https://avatars.discourse-cdn.com/v4/letter/s/a88e57/32.png) [@sanders\_2345](https://discuss.elastic.co/u/sanders_2345)\
**Post date:** [February 7, 2022, 7:26am UTC](https://discuss.elastic.co/t/include-exclude-of-500k-ids-in-a-search-query/296428/1 "2022-02-07T07:26:23Z")

</div>

Problem statement:  
We've millions of ids stored in another Id store. These ids we're generating from the application & will be as same es doc id. Here, for certain use-cases, we want to include & exclude these ids in a search query. Looked into the "ids" query not sure about the limitation there. Also, is there a plugin available that makes Elasticsearch interacts with another data store directly, fetch the ids during query execution?

ES version: 6.4

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 7, 2022, 8:12am UTC](https://discuss.elastic.co/t/include-exclude-of-500k-ids-in-a-search-query/296428/2 "2022-02-07T08:12:23Z")

</div>

Welcome to our community! 😃

> [@sanders\_2345](#):
>
> Looked into the "ids" query not sure about the limitation there

It might work, you'd be better off with a filter, but that's still a huge number.

> [@sanders\_2345](#):
>
> Also, is there a plugin available that makes Elasticsearch interacts with another data store directly, fetch the ids during query execution?

No, there's not.

> [@sanders\_2345](#):
>
> ES version: 6.4

That's [EOL](https://www.elastic.co/support/eol) and no longer supported. Latest is 7.17 and 8.0 is not far off being GA. You should really upgrade as a matter of urgency.

---

<div class="post-metadata">

**Author:** ![sanders\_2345](https://avatars.discourse-cdn.com/v4/letter/s/a88e57/32.png) [@sanders\_2345](https://discuss.elastic.co/u/sanders_2345)\
**Post date:** [February 7, 2022, 5:08pm UTC](https://discuss.elastic.co/t/include-exclude-of-500k-ids-in-a-search-query/296428/3 "2022-02-07T17:08:26Z")

</div>

Thanks Mark for the reply. Any suggestion to implement this?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [February 7, 2022, 10:03pm UTC](https://discuss.elastic.co/t/include-exclude-of-500k-ids-in-a-search-query/296428/4 "2022-02-07T22:03:34Z")

</div>

Large lists of ids will always be a challenge  
You may be interested in a script and some benchmarking [here](https://github.com/elastic/elasticsearch/issues/74954#issuecomment-876363500) that shows speed-ups under certain conditions

---

<div class="post-metadata">

**Author:** ![sanders\_2345](https://avatars.discourse-cdn.com/v4/letter/s/a88e57/32.png) [@sanders\_2345](https://discuss.elastic.co/u/sanders_2345)\
**Post date:** [February 8, 2022, 12:32pm UTC](https://discuss.elastic.co/t/include-exclude-of-500k-ids-in-a-search-query/296428/5 "2022-02-08T12:32:52Z")

</div>

Thanks @Mark_Harwood, will go through.

---

<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:** [March 12, 2022, 7:06pm UTC](https://discuss.elastic.co/t/include-exclude-of-500k-ids-in-a-search-query/296428/7 "2022-03-12T19:06:49Z")

</div>

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