# Access Object field type doc value in function score query

**URL:** <https://discuss.elastic.co/t/access-object-field-type-doc-value-in-function-score-query/73645>\
**Category:** Elasticsearch\
**Created:** [February 2, 2017, 9:29am UTC](https://discuss.elastic.co/t/access-object-field-type-doc-value-in-function-score-query/73645 "2017-02-02T09:29:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![heeren](https://avatars.discourse-cdn.com/v4/letter/h/a3d4f5/32.png) [@heeren](https://discuss.elastic.co/u/heeren)\
**Post date:** [February 2, 2017, 9:29am UTC](https://discuss.elastic.co/t/access-object-field-type-doc-value-in-function-score-query/73645/1 "2017-02-02T09:29:54Z")

</div>

Version ES:2.4  
In document, I have field called "domain\_score" which is an Object type. e.g.  
`{"field1": {"de": {"de": 2} } }`  
Default value of this field is {} i.e empty dictionary.  
In my scoring script I am applying two parameters, language and country. My script looked something like this.

```
float boost = 0.0;
domain_score = doc["domain_score"].value ;
isCountry = doc["domain_score"].get(country) ;
if (isCountry != null) {
    isLanguage = doc["domain_score"][country].get(language)
    if (isLanguage != null) {
        val = doc["domain_score"][country][language]
        if (val > 0) {
            boost = val 
        }
    }
} ;
return boost ;

```

Its giving me the error that its not a correct groovy script.

---

<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:** [March 2, 2017, 9:30am UTC](https://discuss.elastic.co/t/access-object-field-type-doc-value-in-function-score-query/73645/2 "2017-03-02T09:30:40Z")

</div>

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