# Best way to model a query on 10K ORs?

**URL:** https://discuss.elastic.co/t/best-way-to-model-a-query-on-10k-ors/37941
**Category:** Elasticsearch
**Created:** [December 24, 2015, 1:32pm UTC](https://discuss.elastic.co/t/best-way-to-model-a-query-on-10k-ors/37941 "2015-12-24T13:32:01Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![aliostad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aliostad/32/4046_2.png) [@aliostad](https://discuss.elastic.co/u/aliostad)
#### Post date: [December 24, 2015, 1:32pm UTC](https://discuss.elastic.co/t/best-way-to-model-a-query-on-10k-ors/37941/1 "2015-12-24T13:32:01Z")

</div>

I know this sounds like a strange question but I am looking for the sanest way to achieve this:

I have a list of ~10K ProductIds coming from a ML engine and I need to create filters and facets on the top of this list, where the product metadata is stored in ES. I am trying to find the best way to pass this list as a parameter which is 1) not too verbose 2) performant.

I can create a filter and pass 10K OR terms statements but that sounds like really freaky.

Is there a better way to do this? Also can consider change in data modelling.

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [December 24, 2015, 1:52pm UTC](https://discuss.elastic.co/t/best-way-to-model-a-query-on-10k-ors/37941/2 "2015-12-24T13:52:52Z")

</div>

The least insane way to do it would be to use a `terms` query.

---

<div class="post-metadata">

### Author: ![aliostad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aliostad/32/4046_2.png) [@aliostad](https://discuss.elastic.co/u/aliostad)
#### Post date: [December 24, 2015, 2:59pm UTC](https://discuss.elastic.co/t/best-way-to-model-a-query-on-10k-ors/37941/3 "2015-12-24T14:59:21Z")

</div>

> [@aliostad](#):
>
> The least insane way to do it would be to use a terms query.

So you mean a 10K OR filter? OK, thanks I will give it a go and let you know how it works.

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [December 24, 2015, 3:11pm UTC](https://discuss.elastic.co/t/best-way-to-model-a-query-on-10k-ors/37941/4 "2015-12-24T15:11:46Z")

</div>

I'm not sure what you mean by a OR query, but this is the terms query I was thinking about: [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html)

---

<div class="post-metadata">

### Author: ![aliostad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aliostad/32/4046_2.png) [@aliostad](https://discuss.elastic.co/u/aliostad)
#### Post date: [December 24, 2015, 3:28pm UTC](https://discuss.elastic.co/t/best-way-to-model-a-query-on-10k-ors/37941/5 "2015-12-24T15:28:18Z")

</div>

Gotcha! Terms not Term... I did not really dig the difference 🙂

---

<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: [July 5, 2017, 11:28pm UTC](https://discuss.elastic.co/t/best-way-to-model-a-query-on-10k-ors/37941/6 "2017-07-05T23:28:48Z")

</div>


