ES版本:number: "7.0.1",
以下查询不起作用。它返回illegal_argument_exception
(下面是完整堆栈)。
{
"query": {
"function_score": {
"query": {
"query_string": {
"query": "SOME_QUERY"
}
},"script_score": {
"script": {
"source": "Math.log(doc['SOME_FIELD'].value + 1)"
}
}
}
}
}
尽管我可能会遇到doc['SOME_FIELD'].value
的问题,但显然在使用运算符(在这种情况下为Math.*
)的+
函数中存在语法问题:
-
"source": "Math.log(doc['SOME_FIELD'].value + 1)"
不起作用 -
"source": "Math.log(1 + 1)"
不起作用
同时
-
"source": "doc['SOME_FIELD'].value"
作品 -
"source": "1 + 1"
作品 -
"source": "Math.log(1)"
作品
全栈跟踪:
{
"error": {
"root_cause": [
{
"type": "script_exception","reason": "compile error","script_stack": [
"NaN","^---- HERE"
],"script": "NaN","lang": "painless"
}
],"type": "search_phase_execution_exception","reason": "all shards failed","phase": "query","grouped": true,"failed_shards": [
{
"shard": 0,"index": "index","node": "69HAL8sMS-afWoTxhMteKw","reason": {
"type": "query_shard_exception","reason": "script_score: the script could not be loaded","index_uuid": "ASy6y5zxRpqMFONSLED6IQ","caused_by": {
"type": "script_exception","script_stack": [
"NaN","^---- HERE"
],"lang": "painless","caused_by": {
"type": "illegal_argument_exception","reason": "Variable [NaN] is not defined."
}
}
}
}
],"caused_by": {
"type": "script_exception","script_stack": [
"NaN","^---- HERE"
],"caused_by": {
"type": "illegal_argument_exception","reason": "Variable [NaN] is not defined."
}
}
},"status": 400
}