# Issues when running groovy script for "function\_score"?

**URL:** <https://discuss.elastic.co/t/issues-when-running-groovy-script-for-function-score/21867>\
**Category:** Elasticsearch\
**Created:** [January 28, 2015, 3:44am UTC](https://discuss.elastic.co/t/issues-when-running-groovy-script-for-function-score/21867 "2015-01-28T03:44:29Z")\
**Posts on this page:** 4\
**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:44am UTC](https://discuss.elastic.co/t/issues-when-running-groovy-script-for-function-score/21867/1 "2015-01-28T03:44:29Z")

</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 this?

--  
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/904247f3-5df0-4b1d-b509-80d4d606745b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/904247f3-5df0-4b1d-b509-80d4d606745b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [January 28, 2015, 5:21am UTC](https://discuss.elastic.co/t/issues-when-running-groovy-script-for-function-score/21867/2 "2015-01-28T05:21:22Z")

</div>

Hi ,

What is terms here ?  
As far as i know , there is no provisions to get all terms for a field for  
a document by default.  
Only work around is to use term vectors  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-advanced-scripting.html#\_term\_vectors](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-advanced-scripting.html#_term_vectors)  
.

Thanks  
Vineeth Mohan,  
Elasticsearch consultant,  
[qbox.io](http://qbox.io) ( Elasticsearch service provider [http://qbox.io/](http://qbox.io/))

On Wed, Jan 28, 2015 at 9:14 AM, Panzer [appythoncheck@gmail.com](mailto:appythoncheck@gmail.com) wrote:

> 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 this?
> 
> --  
> 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/904247f3-5df0-4b1d-b509-80d4d606745b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/904247f3-5df0-4b1d-b509-80d4d606745b%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/904247f3-5df0-4b1d-b509-80d4d606745b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/904247f3-5df0-4b1d-b509-80d4d606745b%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAGdPd5kCxRwZoyMoM%3D0NZ8vKiHqXSKm0DrT9wuEmGRaRh8W5BQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5kCxRwZoyMoM%3D0NZ8vKiHqXSKm0DrT9wuEmGRaRh8W5BQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![siddharth\_gupta](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@siddharth\_gupta](https://discuss.elastic.co/u/siddharth_gupta)\
**Post date:** [September 20, 2015, 10:33am UTC](https://discuss.elastic.co/t/issues-when-running-groovy-script-for-function-score/21867/3 "2015-09-20T10:33:16Z")

</div>

Hello @vineeth_mohan_2

I have stored the term vectors still I am facing the below issue:

nested: GroovyScriptExecutionException[MissingPropertyException[No such property: terms for class: 6f0f3a10c46d99c0dac250c63bc1db72285438d4]];

Can you please help ?

Thanks  
Siddharth

---

<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 5, 2017, 11:49pm UTC](https://discuss.elastic.co/t/issues-when-running-groovy-script-for-function-score/21867/4 "2017-07-05T23:49:14Z")

</div>


