# Search API vs Count API performance?

**URL:** <https://discuss.elastic.co/t/search-api-vs-count-api-performance/126544>\
**Category:** Elasticsearch\
**Created:** [April 3, 2018, 10:11am UTC](https://discuss.elastic.co/t/search-api-vs-count-api-performance/126544 "2018-04-03T10:11:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gskema](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gskema/32/13648_2.png) [@gskema](https://discuss.elastic.co/u/gskema)\
**Post date:** [April 3, 2018, 10:11am UTC](https://discuss.elastic.co/t/search-api-vs-count-api-performance/126544/1 "2018-04-03T10:11:39Z")

</div>

Recently we made changes to our code, where we replaced a search request (with aggs, score functions, etc.) with a count request. The problem is that we can't monitor count requests with a `stats` group.

Someone claimed that count API internally runs a trimmed down search request and if we sent an equivalent "trimmed down search request" (no aggs, no score functions, size:0, filter context) the performance would be almost the same + we could monitor it with `stats` group.

- Is there a way besides raw HTTP time to compare the two?
- Is count API more optimized for this?

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [April 6, 2018, 11:26am UTC](https://discuss.elastic.co/t/search-api-vs-count-api-performance/126544/2 "2018-04-06T11:26:54Z")

</div>

Hi @gskema,

the count API issues a search request under the hood indeed. You can have a look at the [source code of RestCountAction](https://github.com/elastic/elasticsearch/blob/55c8e80/server/src/main/java/org/elasticsearch/rest/action/document/RestCountAction.java#L64-L107) to see how it uses the search API.

To your questions:

> Is there a way besides raw HTTP time to compare the two?

Unfortunately, I don't quite understand what you are after here.

> Is count API more optimized for this?

As you can see in the source code, it is really just issues a search request under the hood, so: no.

Daniel

---

<div class="post-metadata">

**Author:** ![gskema](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gskema/32/13648_2.png) [@gskema](https://discuss.elastic.co/u/gskema)\
**Post date:** [April 6, 2018, 4:41pm UTC](https://discuss.elastic.co/t/search-api-vs-count-api-performance/126544/3 "2018-04-06T16:41:20Z")

</div>

Thanks for answering @danielmitterdorfer

By asking

> Is there a way besides raw HTTP time to compare the two?

I wanted to know if `_count` API supports something like` stat groups` or has `response.took` so we can measure the load on our servers. We already switched to plain search request so we could track the load with a stat group, which was unavailable for `_count` request

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [April 9, 2018, 6:03am UTC](https://discuss.elastic.co/t/search-api-vs-count-api-performance/126544/4 "2018-04-09T06:03:32Z")

</div>

Ah, I see. No, it is not possible to use stats groups or get `took` in the response.

---

<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:** [May 7, 2018, 6:03am UTC](https://discuss.elastic.co/t/search-api-vs-count-api-performance/126544/5 "2018-05-07T06:03:55Z")

</div>

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