# Accessing non nested fields in a nested query

**URL:** <https://discuss.elastic.co/t/accessing-non-nested-fields-in-a-nested-query/19030>\
**Category:** Elasticsearch\
**Created:** [August 1, 2014, 2:03pm UTC](https://discuss.elastic.co/t/accessing-non-nested-fields-in-a-nested-query/19030 "2014-08-01T14:03:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sindhuja](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@sindhuja](https://discuss.elastic.co/u/sindhuja)\
**Post date:** [August 1, 2014, 2:03pm UTC](https://discuss.elastic.co/t/accessing-non-nested-fields-in-a-nested-query/19030/1 "2014-08-01T14:03:36Z")

</div>

Hi,

I have a JSON object called listofjsons which looks like this :  
"listofjsons": [  
{  
"Link": "[http://dbpedia.org/page/Category:Statistics\_Canada](http://dbpedia.org/page/Category:Statistics_Canada)",  
"score": 2,  
"context": "",  
"frequency": 1,  
"Entity": "Statistics Canada"  
},  
{  
"Link": "[http://dbpedia.org/page/Gain](http://dbpedia.org/page/Gain)",  
"score": 3,  
"context": "",  
"frequency": 1,  
"Entity": "Gain"  
}  
]

and then I have a non nested field called maxFrequency. I have a complex formula to calculate based on matched entities, in which I need to use both score and frequency of every matched entity and also the maxfrequency of the document.

I am using this query :

{  
"query": {  
"nested": {  
"path": "listofjsons",  
"score\_mode": "total",  
"query": {  
"function\_score": {  
"query": {  
"bool": {  
"should": [  
{  
"terms": {  
"listofjsons.Entity": [  
"Canada","Oil","Gas"  
]  
}  
}  
]  
}  
},  
"boost\_mode": "replace",  
"script\_score": {  
"script": "0.5_doc['listofjsons.score'].value_doc['listofjsons.frequency'].value/10;"  
}  
}  
}  
}  
}  
}  
}  
}

How do i access "maxFrequency " inside the nested query.

---

<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:** [July 6, 2017, 1:11am UTC](https://discuss.elastic.co/t/accessing-non-nested-fields-in-a-nested-query/19030/2 "2017-07-06T01:11:40Z")

</div>


