# Strange behavior while trying to access the score of a document within a script

**URL:** https://discuss.elastic.co/t/strange-behavior-while-trying-to-access-the-score-of-a-document-within-a-script/79918
**Category:** Elasticsearch
**Created:** [March 24, 2017, 3:47pm UTC](https://discuss.elastic.co/t/strange-behavior-while-trying-to-access-the-score-of-a-document-within-a-script/79918 "2017-03-24T15:47:08Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Tobias\_Sturzenegger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tobias_sturzenegger/32/16705_2.png) [@Tobias\_Sturzenegger](https://discuss.elastic.co/u/Tobias_Sturzenegger)
#### Post date: [March 24, 2017, 3:47pm UTC](https://discuss.elastic.co/t/strange-behavior-while-trying-to-access-the-score-of-a-document-within-a-script/79918/1 "2017-03-24T15:47:08Z")

</div>

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](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](http://localhost:9200/my_index/my_type/1) -d'  
{  
"text": "quick brown fox",  
"popularity": 1  
}'

curl [http://localhost:9200/my\_index/\_search](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

---

<div class="post-metadata">

### Author: ![Tobias\_Sturzenegger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tobias_sturzenegger/32/16705_2.png) [@Tobias\_Sturzenegger](https://discuss.elastic.co/u/Tobias_Sturzenegger)
#### Post date: [March 27, 2017, 10:43am UTC](https://discuss.elastic.co/t/strange-behavior-while-trying-to-access-the-score-of-a-document-within-a-script/79918/2 "2017-03-27T10:43:41Z")

</div>

If someone else runs into that problem. It was a unicode problem.  
Instead of:

doc['popularity']

use

doc[\u0027popularity\u0027]

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [April 24, 2017, 10:43am UTC](https://discuss.elastic.co/t/strange-behavior-while-trying-to-access-the-score-of-a-document-within-a-script/79918/3 "2017-04-24T10:43:42Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
