Hi
I encountered a strange behavior while trying to access the score of a document within a script.
My elasticsearch version:
"version" : {
"number" : "5.2.2",
"build_hash" : "f9d9b74",
"build_date" : "2017-02-24T17:26:45.835Z",
"build_snapshot" : false,
"lucene_version" : "6.4.1"
I tried to follow the guideline from: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/modules-scripting-fields.html
I put following commands into my system:
curl -XPUT http://localhost:9200/my_index/my_type/1 -d'
{
"text": "quick brown fox",
"popularity": 1
}'
curl http://localhost:9200/my_index/_search -d'
{
"query": {
"function_score": {
"query": {
"match": {
"text": "quick brown fox"
}
},
"script_score": {
"script": {
"lang": "expression",
"inline": "_score * doc['popularity']"
}
}
}
}
}'
I got the following error message:
{"error":{"root_cause":[{"type":"script_exception","reason":"compile error","script_stack":["doc[my_field] * multiplier"," ^---- HERE"],"script":"doc[my_field] * multiplier","lang":"expression"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"my_index","node":"FtR3JCuSR9uGVUoqRu6cuw","reason":{"type":"script_exception","reason":"compile error","caused_by":{"type":"parse_exception","reason":"unexpected character '[' on line (1) position (3)","caused_by":{"type":"lexer_no_viable_alt_exception","reason":null}},"script_stack":["doc[my_field] * multiplier"," ^---- HERE"],"script":"doc[my_field] * multiplier","lang":"expression"}}],"caused_by":{"type":"script_exception","reason":"compile error","caused_by":{"type":"parse_exception","reason":"unexpected character '[' on line (1) position (3)","caused_by":{"type":"lexer_no_viable_alt_exception","reason":null}},"script_stack":["doc[my_field] * multiplier"," ^---- HERE"],"script":"doc[my_field] * multiplier","lang":"expression"}},"status":500}
Can someone help?
Kind regards