# Accessing term frequency using function\_score query script\_score option to compute custom score

**URL:** <https://discuss.elastic.co/t/accessing-term-frequency-using-function-score-query-script-score-option-to-compute-custom-score/161805>\
**Category:** Elasticsearch\
**Created:** [December 21, 2018, 8:07am UTC](https://discuss.elastic.co/t/accessing-term-frequency-using-function-score-query-script-score-option-to-compute-custom-score/161805 "2018-12-21T08:07:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ManasaP](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@ManasaP](https://discuss.elastic.co/u/ManasaP)\
**Post date:** [December 21, 2018, 8:07am UTC](https://discuss.elastic.co/t/accessing-term-frequency-using-function-score-query-script-score-option-to-compute-custom-score/161805/1 "2018-12-21T08:07:28Z")

</div>

Hi,

I am planning to implement custom scoring using function score query. I want the scores to be based on term frequencies in the document. It was possible in earlier versions of elastic search to access the term frequency in the script query using \_index field i.e. \_index[field][term].tf(). How can we achieve this in latest version of elastic search since \_index[field][term].tf() is deprecated now?

How to achive this in latest version on elastic search?  
{  
"script\_score": {  
"script": {"inline": "\_index[field][term].tf()"}  
},  
"weight": 100  
}

Thanks,  
Manasa

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [December 21, 2018, 7:39pm UTC](https://discuss.elastic.co/t/accessing-term-frequency-using-function-score-query-script-score-option-to-compute-custom-score/161805/2 "2018-12-21T19:39:11Z")

</div>

You will need to write an elasticsearch plugin to achieve this. See the [advanced scripting example](https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-engine.html) in the docs.

---

<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:** [January 18, 2019, 7:39pm UTC](https://discuss.elastic.co/t/accessing-term-frequency-using-function-score-query-script-score-option-to-compute-custom-score/161805/3 "2019-01-18T19:39:24Z")

</div>

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