# Count number of occurrence of specific keyword from specific field in all docs

**URL:** https://discuss.elastic.co/t/count-number-of-occurrence-of-specific-keyword-from-specific-field-in-all-docs/272415
**Category:** Elasticsearch
**Created:** [May 7, 2021, 12:07pm UTC](https://discuss.elastic.co/t/count-number-of-occurrence-of-specific-keyword-from-specific-field-in-all-docs/272415 "2021-05-07T12:07:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![vradder](https://avatars.discourse-cdn.com/v4/letter/v/898d66/32.png) [@vradder](https://discuss.elastic.co/u/vradder)
#### Post date: [May 7, 2021, 12:07pm UTC](https://discuss.elastic.co/t/count-number-of-occurrence-of-specific-keyword-from-specific-field-in-all-docs/272415/1 "2021-05-07T12:07:43Z")

</div>

Hello ES Team,

I am looking for query in aggregation to find total number of occurrence of specific keyword from specific field in all doc.  
Example:  
doc1 - {logEntry: 'allow\_edit\_gos=true, allow\_gos\_edit=false'}  
doc2 - {logEntry: 'allow\_edit\_gos=x, allow\_gos\_edit=x'}

how do i find "allow" keyword count to 4 in above 2 documents ?

Right now i am using below query which return 2 because it finds number doc which has "allow" keyword in it, but i am looking for total keyword occurrence counts instead of total doc count.  
esb.requestBodySearch().aggs(esb.matchPhrasePrefixQuery('logEntry', 'allow'))

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: [June 4, 2021, 12:07pm UTC](https://discuss.elastic.co/t/count-number-of-occurrence-of-specific-keyword-from-specific-field-in-all-docs/272415/2 "2021-06-04T12:07:49Z")

</div>

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