# Getting phrase count for each document separately

**URL:** <https://discuss.elastic.co/t/getting-phrase-count-for-each-document-separately/17082>\
**Category:** Elasticsearch\
**Created:** [April 18, 2014, 4:05pm UTC](https://discuss.elastic.co/t/getting-phrase-count-for-each-document-separately/17082 "2014-04-18T16:05:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amit\_3](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@Amit\_3](https://discuss.elastic.co/u/Amit_3)\
**Post date:** [April 18, 2014, 4:05pm UTC](https://discuss.elastic.co/t/getting-phrase-count-for-each-document-separately/17082/1 "2014-04-18T16:05:12Z")

</div>

I would like to get a phrase count for each document separately.  
I do not wish to run a query for every document, i would rather run one  
single query.

For example if i have the following documents:  
{  
"name" : "John",  
"message" : "The lion is \*very \*_fast_"  
}

{  
"name" : "Ben",  
"message" : "The lion is \*very \*_fast_ and the bardelas is _very fast_  
"

}

I would like to query my documents for the phrase "_very fast_" and get  
back something like this:  
{  
"name" : "John",  
"message" : "The lion is \*very \*_fast_",  
_"count" : 1_

}

{  
"name" : "Ben",  
"message" : "The lion is \*very \*_fast_ and the bardelas is _very  
fast_",  
_"count" : 2_  
}

I failed to find out how to do this so far. I only found queries that give  
the total number of documents that contain the phrase (in my example 2  
documents).  
How can I do this using elastic search query?  
Thanks in advance.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3f1aefe9-97fa-44ba-a4b1-644536bd2a5c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3f1aefe9-97fa-44ba-a4b1-644536bd2a5c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:35am UTC](https://discuss.elastic.co/t/getting-phrase-count-for-each-document-separately/17082/2 "2017-07-06T01:35:00Z")

</div>


