# Number Of Occurrences Of A Particular Word in a field

**URL:** <https://discuss.elastic.co/t/number-of-occurrences-of-a-particular-word-in-a-field/129569>\
**Category:** Kibana\
**Created:** [April 25, 2018, 8:44pm UTC](https://discuss.elastic.co/t/number-of-occurrences-of-a-particular-word-in-a-field/129569 "2018-04-25T20:44:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michel\_Budimbu-Esuku](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michel_budimbu-esuku/32/30558_2.png) [@Michel\_Budimbu-Esuku](https://discuss.elastic.co/u/Michel_Budimbu-Esuku)\
**Post date:** [April 25, 2018, 8:44pm UTC](https://discuss.elastic.co/t/number-of-occurrences-of-a-particular-word-in-a-field/129569/1 "2018-04-25T20:44:56Z")

</div>

I index my emails in Kibana. And I would like to know the number of times that the word "timeout" appears in "Emailbody" field.  
{  
"From":"string",  
"To" : "string",  
"Date" "date"  
"Emailbody": "string"  
}

Thank you in advance for your help.

Michael B.

---

<div class="post-metadata">

**Author:** ![Joe\_Fleming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_fleming/32/3561_2.png) [@Joe\_Fleming](https://discuss.elastic.co/u/Joe_Fleming)\
**Post date:** [April 25, 2018, 9:20pm UTC](https://discuss.elastic.co/t/number-of-occurrences-of-a-particular-word-in-a-field/129569/2 "2018-04-25T21:20:37Z")

</div>

This is more an Elasticsearch question. Assuming that the field is named `emailbody`, is the field configured to be analyzed in ES? If so, you can use the [Lucene Query Syntax](https://www.elastic.co/guide/en/kibana/current/lucene-query.html) to find all documents that have that work in the field, which would be `emailbody:timeout`. Putting that in the Kibana query bar will filter the documents returned, and then you could get the count of the documents.

---

<div class="post-metadata">

**Author:** ![Michel\_Budimbu-Esuku](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michel_budimbu-esuku/32/30558_2.png) [@Michel\_Budimbu-Esuku](https://discuss.elastic.co/u/Michel_Budimbu-Esuku)\
**Post date:** [April 26, 2018, 8:57am UTC](https://discuss.elastic.co/t/number-of-occurrences-of-a-particular-word-in-a-field/129569/3 "2018-04-26T08:57:01Z")

</div>

Thank you very much for your proposal.  
I try it right away and I inform you of the result.

Best regards  
Michael B.

---

<div class="post-metadata">

**Author:** ![Michel\_Budimbu-Esuku](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michel_budimbu-esuku/32/30558_2.png) [@Michel\_Budimbu-Esuku](https://discuss.elastic.co/u/Michel_Budimbu-Esuku)\
**Post date:** [April 27, 2018, 12:01pm UTC](https://discuss.elastic.co/t/number-of-occurrences-of-a-particular-word-in-a-field/129569/4 "2018-04-27T12:01:49Z")

</div>

Hello Joe,  
it works perfectly I get the count of the documents  
but I would like to know: The number of times that the word "timeout" is repeated  
on the emailbody field for each document?  
Thank you in advance for your help 🙂

---

<div class="post-metadata">

**Author:** ![Joe\_Fleming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_fleming/32/3561_2.png) [@Joe\_Fleming](https://discuss.elastic.co/u/Joe_Fleming)\
**Post date:** [May 10, 2018, 5:42pm UTC](https://discuss.elastic.co/t/number-of-occurrences-of-a-particular-word-in-a-field/129569/5 "2018-05-10T17:42:18Z")

</div>

Oh, I misunderstood what you were trying to see, sorry about that.

As you can see, Elasticsearch will give you the documents that contain the term pretty easily, but I don't know if there's a way to get the count of times a word was used in a field. Looking at the API, I don't see anything that looks like it'll do that, at least not directly.

I think you _can_ do this with a [scripted field](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-script-fields.html) though. I haven't tried it, but the idea would be to just use a term filter like you are now, and have a script field that would split that value by spaces, and then someone filter by the word you want and then count the remaining items. It would probably be crazy slow, but it would work.

The better way to do this would be to enrich the data when you index it, effectively doing the term count just the one time, and indexing the result along with everything else. This only works if you know ahead of time what term or terms you care about, but it sounds like maybe you do in this case. For existing documents, you can pretty easily [reindex them](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html).

---

<div class="post-metadata">

**Author:** ![Michel\_Budimbu-Esuku](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michel_budimbu-esuku/32/30558_2.png) [@Michel\_Budimbu-Esuku](https://discuss.elastic.co/u/Michel_Budimbu-Esuku)\
**Post date:** [May 11, 2018, 7:32am UTC](https://discuss.elastic.co/t/number-of-occurrences-of-a-particular-word-in-a-field/129569/6 "2018-05-11T07:32:18Z")

</div>

Thank you i will try it 🙂

---

<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 8, 2018, 7:32am UTC](https://discuss.elastic.co/t/number-of-occurrences-of-a-particular-word-in-a-field/129569/7 "2018-06-08T07:32:26Z")

</div>

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