Terms Aggregation with a Script not working

In the ES doc under Terms Aggregations, it gives the following on using a script to generate terms for Aggregations:

Generating the terms using a script:

GET /_search
{
"aggs" : {
"genres" : {
"terms" : {
"script" : {
"source": "doc['genre'].value",
"lang": "painless"
}
}
}
}
}

This is not working for me. In the Kibana Console, I see the results:

{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[terms] failed to parse field [script]",
"line": 6,
"col": 21
}
],
"type": "parsing_exception",
"reason": "[terms] failed to parse field [script]",
"line": 6,
"col": 21,
"caused_by": {
"type": "illegal_argument_exception",
"reason": "[script] unknown field [source], parser not found"
}
},
"status": 400
}

Of course I also adapted this query to my own specific index, type, and fields, with the same result.

I really do need this to work because I have 2 fields that need to be combined to generate the buckets I need.

I am using ES 5.3, since that is in production, but we could change if this is something fixed in a later version.

Some help would be most appreciated. Hopefully it is just a small issue or mistake on my part. I have worked with scripts in aggregations in the same production environment without problems, but haven't before tried to do this specifically.

Thank you!

Patrick

This is the doc for 5.3: https://www.elastic.co/guide/en/elasticsearch/reference/5.3/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-script

Use inline for this version. Or upgrade to 5.6

Initially I thought I had set the doc version to 5.3 and tried that and got the same error. I then tried 6.0 and Master, which I thought were identical. My error.

Thanks so much, David. You saved me a lot of frustration!

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