# Total count of matched phrase in each result document

**URL:** https://discuss.elastic.co/t/total-count-of-matched-phrase-in-each-result-document/116815
**Category:** Elasticsearch
**Created:** [January 24, 2018, 6:48am UTC](https://discuss.elastic.co/t/total-count-of-matched-phrase-in-each-result-document/116815 "2018-01-24T06:48:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![elastic1](https://avatars.discourse-cdn.com/v4/letter/e/f17d59/32.png) [@elastic1](https://discuss.elastic.co/u/elastic1)
#### Post date: [January 24, 2018, 6:48am UTC](https://discuss.elastic.co/t/total-count-of-matched-phrase-in-each-result-document/116815/1 "2018-01-24T06:48:04Z")

</div>

Hi everyone,

Thanks for the great software!  
I have a query about total hit count across multiple documents, where one document can have more than 1 hit for my search term.  
So let's say my search term is "information", and the word exists 50 times in 27 documents in multiple fields ( covered in my search query ).  
Now how do I get this number, which is '50' in my example above?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 24, 2018, 8:35am UTC](https://discuss.elastic.co/t/total-count-of-matched-phrase-in-each-result-document/116815/2 "2018-01-24T08:35:21Z")

</div>

The first thing that came to my mind is [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html) but it will work only on keyword fields if you run first a terms agg and valuecount sub agg I guess.

But then I realized that you might be able to find this information by using `"explain": true` in your query. Although I don't recommend using that in production as it would slowdown the search.

---

<div class="post-metadata">

### Author: ![manasguduri](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@manasguduri](https://discuss.elastic.co/u/manasguduri)
#### Post date: [January 28, 2018, 7:42pm UTC](https://discuss.elastic.co/t/total-count-of-matched-phrase-in-each-result-document/116815/3 "2018-01-28T19:42:11Z")

</div>

Satyaveer, did you get a solution to your problem ? Am also searching for the same, I wonder even is it possible using Elasticsearch, because I can't see a proper solution for that by anyone !

Please, reply me if you found a way how to do it !!

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: [February 25, 2018, 7:42pm UTC](https://discuss.elastic.co/t/total-count-of-matched-phrase-in-each-result-document/116815/4 "2018-02-25T19:42:33Z")

</div>

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