# How to get term frequency in Elastic Search 5.6

**URL:** <https://discuss.elastic.co/t/how-to-get-term-frequency-in-elastic-search-5-6/101577>\
**Category:** Elasticsearch\
**Created:** [September 23, 2017, 5:54pm UTC](https://discuss.elastic.co/t/how-to-get-term-frequency-in-elastic-search-5-6/101577 "2017-09-23T17:54:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hchovatia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hchovatia/32/22451_2.png) [@hchovatia](https://discuss.elastic.co/u/hchovatia)\
**Post date:** [September 23, 2017, 5:54pm UTC](https://discuss.elastic.co/t/how-to-get-term-frequency-in-elastic-search-5-6/101577/1 "2017-09-23T17:54:42Z")

</div>

Here is my ES Queries:  
=== Create the index ===  
`PUT /sample`

=== Insert Data ===  
PUT /sample/docs/1  
{"data": "And the world said, 'Disarm, disclose, or face serious consequences'—and therefore, we worked with the world, we worked to make sure that Saddam Hussein heard the message of the world."}  
PUT /sample/docs/2  
{"data": "Never give in — never, never, never, never, in nothing great or small, large or petty, never give in except to convictions of honor and good sense. Never yield to force; never yield to the apparently overwhelming might of the enemy"}

=== Query to Get Results ===  
POST sample/docs/\_search  
{  
"query": {  
"match": {  
"data": "never"  
}  
},  
"highlight": {  
"fields": {  
"data":{}  
}  
}  
}

=== Retrieved Result ===  
...  
"highlight": {  
"data": [  
"_Never_ give in — _never_, _never_, _never_, _never_, in nothing great or small, large or petty, _never_ give",  
" in except to convictions of honour and good sense. _Never_ yield to force; _never_ yield to the apparently overwhelming might of the enemy"  
]  
}

=== Desired Result===  
Required Term Frequency of searched term by document as example below  
Doc Id: 2  
Term Frequency :{  
"never": 8  
}  
I have tried Bucket Aggregation, Terms Aggregation, and other Aggregations but I'm not getting this result. I have search over google and find way to use groovy script [\_index] option but ES-5.6 not support groovy and I don't know how to convert groovy script to painless

Thanks for the help in advance!

---

<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:** [October 21, 2017, 5:55pm UTC](https://discuss.elastic.co/t/how-to-get-term-frequency-in-elastic-search-5-6/101577/2 "2017-10-21T17:55:01Z")

</div>

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