# Count API with Group By field

**URL:** <https://discuss.elastic.co/t/count-api-with-group-by-field/187295>\
**Category:** Elasticsearch\
**Created:** [June 25, 2019, 9:44am UTC](https://discuss.elastic.co/t/count-api-with-group-by-field/187295 "2019-06-25T09:44:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gokul\_Raj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gokul_raj/32/48717_2.png) [@Gokul\_Raj](https://discuss.elastic.co/u/Gokul_Raj)\
**Post date:** [June 25, 2019, 9:44am UTC](https://discuss.elastic.co/t/count-api-with-group-by-field/187295/1 "2019-06-25T09:44:03Z")

</div>

For my application I'm using count API provided by elasticsearch for getting the aggregate value for my search queries in Java using RestHighLevel Client. However I'm facing a situation where I need to get the aggregate based on the currency for which I need to include group by field condition. Any idea on how to add group by condition using count API in Java?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [June 26, 2019, 8:41am UTC](https://discuss.elastic.co/t/count-api-with-group-by-field/187295/2 "2019-06-26T08:41:58Z")

</div>

Hey,

this sounds like in can be done using the search API and an aggregation. Any reason for not doing this?

--Alex

---

<div class="post-metadata">

**Author:** ![Gokul\_Raj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gokul_raj/32/48717_2.png) [@Gokul\_Raj](https://discuss.elastic.co/u/Gokul_Raj)\
**Post date:** [June 27, 2019, 8:42am UTC](https://discuss.elastic.co/t/count-api-with-group-by-field/187295/3 "2019-06-27T08:42:06Z")

</div>

We thought count API would improve the performance but came to know that it uses search API under the hood. So now we are trying to know if grouping is supported in count API else need to go back to search API with aggregation.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [June 27, 2019, 3:32pm UTC](https://discuss.elastic.co/t/count-api-with-group-by-field/187295/4 "2019-06-27T15:32:03Z")

</div>

just go ahead with search API and you will be fine. The count API is simply a wrapper around a search - no performance optimization or anything happens - also there is no grouping, because there are no aggregations.

---

<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 25, 2019, 3:32pm UTC](https://discuss.elastic.co/t/count-api-with-group-by-field/187295/5 "2019-07-25T15:32:13Z")

</div>

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