# Query For Counting specific fields in ES

**URL:** <https://discuss.elastic.co/t/query-for-counting-specific-fields-in-es/86689>\
**Category:** Elasticsearch\
**Created:** [May 22, 2017, 2:39pm UTC](https://discuss.elastic.co/t/query-for-counting-specific-fields-in-es/86689 "2017-05-22T14:39:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ELKibana](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@ELKibana](https://discuss.elastic.co/u/ELKibana)\
**Post date:** [May 22, 2017, 2:39pm UTC](https://discuss.elastic.co/t/query-for-counting-specific-fields-in-es/86689/1 "2017-05-22T14:39:25Z")

</div>

I want to count for eg city appearance in the index and return it back to java. How to do this ?  
I have tried search Response but to no avail.

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [May 26, 2017, 8:33am UTC](https://discuss.elastic.co/t/query-for-counting-specific-fields-in-es/86689/2 "2017-05-26T08:33:14Z")

</div>

You need to provide more information, and show what you have tried

---

<div class="post-metadata">

**Author:** ![ELKibana](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@ELKibana](https://discuss.elastic.co/u/ELKibana)\
**Post date:** [May 26, 2017, 1:18pm UTC](https://discuss.elastic.co/t/query-for-counting-specific-fields-in-es/86689/3 "2017-05-26T13:18:14Z")

</div>

> [@ELKibana](#):
>
> o count for eg city appearance in the index and return it back to java. How to do this ?  
> I have tried search Response but to no avail.

Never mind..I added a terms aggregations with set query method in SearchResponse and success.  
Thanks

---

<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:** [June 23, 2017, 1:18pm UTC](https://discuss.elastic.co/t/query-for-counting-specific-fields-in-es/86689/4 "2017-06-23T13:18:39Z")

</div>

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