Hi. newbie here.
I'm trying to write script_score with params._source, but it returns null pointer exception.
(I want to access nested data)
Query is like this.
GET /users/_search
{
"query": {
"function_score": {
"query" : {
"match_all": {}
},
"score_mode" : "sum",
"boost_mode" : "sum",
"script_score": {
"script": {
"lang": "painless",
"source": "if (params._source['categories'][0]['category_id'] == 3) { 10 } else { -50 }"
}
}
}
}
}
It returns
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"if (params._source['categories'][0]['category_id'] == 3) { ",
" ^---- HERE"
],
"script": "if (params._source['categories'][0]['category_id'] == 3) { 10 } else { -50 }",
"lang": "painless"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "users",
"node": "xxxxxxxxxxxxxxxxx(filtered)",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"if (params._source['categories'][0]['category_id'] == 3) { ",
" ^---- HERE"
],
"script": "if (params._source['categories'][0]['category_id'] == 3) { 10 } else { -50 }",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
}
}
]
},
"status": 500
}
How can I access params['_source'] in script_score?
※ Elasticsearch version ... 6.4.2
params.containsKey('_source')
returns false, params.isEmpty()
returns true ...