ES offers the possibility to store your script within an internal index ( see IndexedScript ), but unfortunately I cannot access it from aggreagtions.
Creating the index:
POST /_scripts/groovy/termFrequency
{
"script": "_index['textBody'][term].tf()"
}
Using the script within aggreagtions:
GET /my_index/_search
{
"query":{
"match_all": {}
},
"aggs":{
"tf_sum":{
"sum":{
"script": {
"script": "termFrequency",
"lang": "groovy",
"params": {"term":"keyword"}
}
}
}
}
}
results in the syntax-error: Parse Failure [Unexpected token START_OBJECT in [tf_sum].
The purpose of the script is, to extract the term frequencies. I don't want to use script_files, because uploading such files is expensive in cloud services (e.g. found).