# How to retrieve values from nested json element while using function in query

**URL:** <https://discuss.elastic.co/t/how-to-retrieve-values-from-nested-json-element-while-using-function-in-query/120033>\
**Category:** Elasticsearch\
**Created:** [February 15, 2018, 4:56pm UTC](https://discuss.elastic.co/t/how-to-retrieve-values-from-nested-json-element-while-using-function-in-query/120033 "2018-02-15T16:56:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![debroy2000](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@debroy2000](https://discuss.elastic.co/u/debroy2000)\
**Post date:** [February 15, 2018, 4:56pm UTC](https://discuss.elastic.co/t/how-to-retrieve-values-from-nested-json-element-while-using-function-in-query/120033/1 "2018-02-15T16:56:23Z")

</div>

I have a Query running against Elastic Search version 5.5.2 where I need to get a custom boost score for a particular document in the scored result so that it goes to the top of the search result based on a particular search term. I am using function and filter to achieve that where I am extracting data from indexed fields.

```
"functions": [
                {
                    "filter": {
                        "match": {
                            " **meta.keyword.value**": "Lorem" . <===- This works
                        }
                    },
                    "script_score": {
                        "script": {
                            "inline": "doc[' **meta.weight_factor**'].value" . <==== This does not work.
                        }
                    }
                }
            ]

Indexed elements will come from this-

"meta": {
.....
"keyword": [
              "Lorem"
            ],
            "weight_factor": [
              "10"
            ] 

}

```

I tried to implement nested query to provide path for "meta", however that is not working since I cannot use nested query at the top level to support the original search query.

So is there any way to grab the "weight\_factor" value inside the function and use that inside "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 15, 2018, 4:56pm UTC](https://discuss.elastic.co/t/how-to-retrieve-values-from-nested-json-element-while-using-function-in-query/120033/2 "2018-03-15T16:56:34Z")

</div>

Closed on March 15, 2018, 4:56pm UTC

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