# Most efficient way to do multiple query counts

**URL:** <https://discuss.elastic.co/t/most-efficient-way-to-do-multiple-query-counts/50371>\
**Category:** Elasticsearch\
**Created:** [May 18, 2016, 7:55pm UTC](https://discuss.elastic.co/t/most-efficient-way-to-do-multiple-query-counts/50371 "2016-05-18T19:55:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick\_Lam](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@Patrick\_Lam](https://discuss.elastic.co/u/Patrick_Lam)\
**Post date:** [May 18, 2016, 7:55pm UTC](https://discuss.elastic.co/t/most-efficient-way-to-do-multiple-query-counts/50371/1 "2016-05-18T19:55:42Z")

</div>

Suppose I have a large index of documents and a list of 500 different independent (query string) queries. I need to get the number of documents that match each of those queries and I need to get the counts as quickly and efficiently as possible. Is there an easy way to do this?

- I could run the count API 500 times, but this is relatively slow.
- I could use the multisearch API and just get back the doc counts of each of the MS search results, but this seems to put a heavy load on my machine.

Is there an easier way to accomplish what I need short of getting more/bigger machines?

---

<div class="post-metadata">

**Author:** ![ddorian43](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ddorian43/32/36093_2.png) [@ddorian43](https://discuss.elastic.co/u/ddorian43)\
**Post date:** [May 19, 2016, 11:57am UTC](https://discuss.elastic.co/t/most-efficient-way-to-do-multiple-query-counts/50371/2 "2016-05-19T11:57:48Z")

</div>

See this thread: [https://github.com/elastic/elasticsearch/issues/17926](https://github.com/elastic/elasticsearch/issues/17926)

I don't think there is a more efficient way beside changing the schema. To lower the load you can split the searches into smaller batches (ex: 50 or 100).

---

<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, 10:50pm UTC](https://discuss.elastic.co/t/most-efficient-way-to-do-multiple-query-counts/50371/3 "2017-07-05T22:50:26Z")

</div>

Closed on July 5, 2017, 10:50pm UTC


