I'm using ES 6.2.4 and online documentation for this version says one should use parameters to optimize scripting. I'm getting a compile error when trying to do so...
GET group/_search
{
"min_score": 1,
"query": {
"function_score": {
"query": {
"bool": {
"must": [
{
"terms": {
"itemId": [
"176947"
]
}
},
{
"match": {
"name": {
"query": "soft drinks",
"operator": "and",
"fuzziness": "AUTO",
"prefix_length": 2
}
}
}
]
}
},
"script_score": {
"script": {
"params": {
"terms": 2
},
"source": "terms / (float)doc['name.length'].value"
}
}
}
}
}
Result:
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"terms / (float)doc['name. ...",
"^---- HERE"
],
"script": "terms / (float)doc['name.length'].value",
"lang": "painless"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "group_20190318_150630",
"node": "L0vkzTvaRTWOBHtU0PYBdQ",
"reason": {
"type": "query_shard_exception",
"reason": "script_score: the script could not be loaded",
"index_uuid": "1Gh7dOv3QXOo_8Ta8wm1_w",
"index": "group_20190318_150630",
"caused_by": {
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"terms / (float)doc['name. ...",
"^---- HERE"
],
"script": "terms / (float)doc['name.length'].value",
"lang": "painless",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Variable [terms] is not defined."
}
}
}
}
],
"caused_by": {
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"terms / (float)doc['name. ...",
"^---- HERE"
],
"script": "terms / (float)doc['name.length'].value",
"lang": "painless",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Variable [terms] is not defined."
}
}
},
"status": 400
}