Compile error when using script with Terms aggregation

Hi,

After upgrading to elastic search 5.4, script with terms aggregation giving compile error which were working properly in previous version 2.3.
I am getting compile error for "list.location" aggregation.
Below is the code snippet for your reference.

GET myindex/mytype/_search
{
"_source": ["id","title","location","country"],
"query": {
something...
},
"aggs":{
"list.location":{
"terms":{
"script": "result=; country = doc['country.untouched'].value + '##'; if (doc['location.untouched'].empty) {country + 'null';} else {for(term in doc['location.untouched'].values){result.add(country + term)}; return result}"
}
}
}
}

Below is attached error screenshot.

Can you please help me to find solution for this..

Thanks :slight_smile:

I got the solution by modifying script as below.

def result=[]; def country = doc['country.untouched'].value + '##'; if (doc['location.untouched'].empty) {country + 'null';} else {for(term in doc['location.untouched'].values){result.add(country + term)} return result}

Thanks (y)

1 Like

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