# Count the occurrence of term in a field of a document

**URL:** https://discuss.elastic.co/t/count-the-occurrence-of-term-in-a-field-of-a-document/22161
**Category:** Elasticsearch
**Created:** [February 13, 2015, 8:29pm UTC](https://discuss.elastic.co/t/count-the-occurrence-of-term-in-a-field-of-a-document/22161 "2015-02-13T20:29:24Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Saurabh\_Agrawal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saurabh_agrawal/32/910_2.png) [@Saurabh\_Agrawal](https://discuss.elastic.co/u/Saurabh_Agrawal)
#### Post date: [February 13, 2015, 8:29pm UTC](https://discuss.elastic.co/t/count-the-occurrence-of-term-in-a-field-of-a-document/22161/1 "2015-02-13T20:29:24Z")

</div>

Greetings,

I have a collection of documents in elastic search index. There is field  
called ABSTRACT\_TEXT which has some text data. I want to search  
this(ABSTRACT\_TEXT) field and count the number of occurrences of the search  
term, say "elastic" in each of the document.

Example: If below is the set of documents:

D1: Elastic is good

D2: Elastic is bad

D3: Elastic is good, but you should use elastic carefully.

If I search for the term "elastic", I want the results to be:

D1: 1

D2: 1

D3: 2

I tried the below query but it returns the count across all documents. I  
need the count per document.

Please help.

--  
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/13f2d833-2f18-4a21-b067-58dc83a0ce2f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/13f2d833-2f18-4a21-b067-58dc83a0ce2f%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, 12:32am UTC](https://discuss.elastic.co/t/count-the-occurrence-of-term-in-a-field-of-a-document/22161/2 "2017-07-06T00:32:50Z")

</div>


