Count the occurrence of term in a field of a document


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
To view this discussion on the web visit
For more options, visit