# Unable to access doc\['field'\].value in script\_score

**URL:** https://discuss.elastic.co/t/unable-to-access-doc-field-value-in-script-score/73012
**Category:** Elasticsearch
**Created:** [January 27, 2017, 12:31pm UTC](https://discuss.elastic.co/t/unable-to-access-doc-field-value-in-script-score/73012 "2017-01-27T12:31:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mv\_es](https://avatars.discourse-cdn.com/v4/letter/m/e5b9ba/32.png) [@mv\_es](https://discuss.elastic.co/u/mv_es)
#### Post date: [January 27, 2017, 12:31pm UTC](https://discuss.elastic.co/t/unable-to-access-doc-field-value-in-script-score/73012/1 "2017-01-27T12:31:19Z")

</div>

I am trying to modify the score of my search results based on the value of two fields, namely "alexaRank" & "pubDate". I get the following **error:**

"caused\_by" : {  
"type" : "missing\_property\_exception",  
"reason" : "No such property: alexaRank for class: e5df54b64e7bd114a1f095ce63f339741dcb4f23"  
}

**The query looks like the following:**

curl -XPOST 'localhost:9200/news\_cluster/\_search?pretty' -d '{  
"explain": true, "query":{ "function\_score" : {  
"query" : {  
"multi\_match" : {  
"query" : "News",  
"fields" : ["title", "url", "description", "content^3"],  
"type" : "phrase",  
"slop" : 10,  
"tie\_breaker" : 0.3  
}  
},  
"functions" : [ {  
"gauss" : {  
"pubDate" : {  
"scale" : "1d",  
"decay" : 0.7  
}  
}  
} ,  
{  
"script\_score" : { "params": {"constant": 100.0, "power": 0.25, "defaultRank": 10000.0} , "script":  
"rank= doc['alexaRank'].value; score=(constant + defaultRank - rank)\*\*power; return score;",  
"lang": "groovy" }} ],  
"score\_mode" : "multiply",  
"boost\_mode" : "multiply",  
"boost" : 2.0  
}  
}}'

**The index mapping is as below:**

"mapping\_cluster" : {  
"mappings" : {  
"articles" : {  
"properties" : {  
"alexaRank" : {  
"type" : "long"  
},  
"content" : {  
"type" : "string"  
},  
"description" : {  
"type" : "string"  
},  
"imageURL" : {  
"type" : "string"  
},  
"pubDate" : {  
"type" : "date",  
"format" : "strict\_date\_optional\_time||epoch\_millis"  
},  
"sourceName" : {  
"type" : "string"  
},  
"title" : {  
"type" : "string"  
},  
"url" : {  
"type" : "string"  
}  
}  
}  
}  
}

Was wondering if somebody could help me figure out what the possible issue is? and how i could access the field to modify its score if this is not the right way.  
I was thinking of using Function Score Query for this purpose initially, but don't know how i can use it to evaluate using the formula i am using currently (with the allowed modifiers).

Thanks!

---

<div class="post-metadata">

### Author: ![mv\_es](https://avatars.discourse-cdn.com/v4/letter/m/e5b9ba/32.png) [@mv\_es](https://discuss.elastic.co/u/mv_es)
#### Post date: [January 27, 2017, 1:00pm UTC](https://discuss.elastic.co/t/unable-to-access-doc-field-value-in-script-score/73012/2 "2017-01-27T13:00:35Z")

</div>

Hi.

Resolved. The quotes were not being escaped.  
changing doc['alexaRank'] to doc[' " ' "alexaRank" ' " '] solved the problem.

---

<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: [February 24, 2017, 1:00pm UTC](https://discuss.elastic.co/t/unable-to-access-doc-field-value-in-script-score/73012/3 "2017-02-24T13:00:42Z")

</div>

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