# Hit count stats for search results

**URL:** <https://discuss.elastic.co/t/hit-count-stats-for-search-results/39690>\
**Category:** Elasticsearch\
**Created:** [January 20, 2016, 6:53pm UTC](https://discuss.elastic.co/t/hit-count-stats-for-search-results/39690 "2016-01-20T18:53:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lifo888](https://avatars.discourse-cdn.com/v4/letter/l/6a8cbe/32.png) [@lifo888](https://discuss.elastic.co/u/lifo888)\
**Post date:** [January 20, 2016, 6:53pm UTC](https://discuss.elastic.co/t/hit-count-stats-for-search-results/39690/1 "2016-01-20T18:53:48Z")

</div>

Hi,

I'm trying to figure out if there's a way to get the number of occurrences for the search phrase for text searches. Say i run a search for the word "apple", i want the results and also how many times "apple" appeared in the matched result. It's ok if i have to run two queries, one to get the normal search result and another query to get the occurrences count.

I know there's the \_explain endpoint and it gives you some of the similar stat, but this [https://www.elastic.co/guide/en/elasticsearch/guide/current/relevance-intro.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/relevance-intro.html) guide says it's expensive and not to use it on production cluster.

Thanks,  
L

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [January 21, 2016, 5:53am UTC](https://discuss.elastic.co/t/hit-count-stats-for-search-results/39690/2 "2016-01-21T05:53:41Z")

</div>

You could probably use a sum agg with a filter for apples.

---

<div class="post-metadata">

**Author:** ![lifo888](https://avatars.discourse-cdn.com/v4/letter/l/6a8cbe/32.png) [@lifo888](https://discuss.elastic.co/u/lifo888)\
**Post date:** [January 21, 2016, 2:01pm UTC](https://discuss.elastic.co/t/hit-count-stats-for-search-results/39690/3 "2016-01-21T14:01:47Z")

</div>

Don't think i can use the sum agg. I want to get the number of occurrences of search phrase in each of the returned docs. Thanks for the reply tho.

Thanks,  
Guang

---

<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:22pm UTC](https://discuss.elastic.co/t/hit-count-stats-for-search-results/39690/4 "2017-07-05T23:22:33Z")

</div>


