# Issues while running Groovy script for "function\_score"?

**URL:** <https://discuss.elastic.co/t/issues-while-running-groovy-script-for-function-score/21866>\
**Category:** Elasticsearch\
**Created:** [January 28, 2015, 3:43am UTC](https://discuss.elastic.co/t/issues-while-running-groovy-script-for-function-score/21866 "2015-01-28T03:43:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Panzer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/panzer/32/927_2.png) [@Panzer](https://discuss.elastic.co/u/Panzer)\
**Post date:** [January 28, 2015, 3:43am UTC](https://discuss.elastic.co/t/issues-while-running-groovy-script-for-function-score/21866/1 "2015-01-28T03:43:08Z")

</div>

def score = 0;  
// terms: list of tokens  
for(term in terms) {  
q\_term\_freq = terms​.countBy { it }​[term];  
term\_freq = \_index[field][term].tf();  
doc\_freq = \_index[field][term].df();  
score += term\_freq \* doc\_freq \* q\_term\_freq;  
};  
score;  
The first one gives an error  
"GroovyScriptExecutionException[MissingPropertyException[No such property:  
terms\u200b for class: Script86". "q\_term\_freq" gives a mapping for a term  
to its frequency.

How should I correct them?

--  
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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c90e889a-f442-46b3-8132-f31be13a58f1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c90e889a-f442-46b3-8132-f31be13a58f1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 12:36am UTC](https://discuss.elastic.co/t/issues-while-running-groovy-script-for-function-score/21866/2 "2017-07-06T00:36:15Z")

</div>


