# Troubles accessing an object array in a nested element with a script

**URL:** <https://discuss.elastic.co/t/troubles-accessing-an-object-array-in-a-nested-element-with-a-script/11038>\
**Category:** Elasticsearch\
**Created:** [March 6, 2013, 5:14pm UTC](https://discuss.elastic.co/t/troubles-accessing-an-object-array-in-a-nested-element-with-a-script/11038 "2013-03-06T17:14:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregor\_G](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@Gregor\_G](https://discuss.elastic.co/u/Gregor_G)\
**Post date:** [March 6, 2013, 5:14pm UTC](https://discuss.elastic.co/t/troubles-accessing-an-object-array-in-a-nested-element-with-a-script/11038/1 "2013-03-06T17:14:50Z")

</div>

Hi all,

I am trying to define a range facet on a value of a nested element that is  
calculated by a script.  
I have an object where level1Array is nested:  
{  
"level1Array":[{  
"level2Array":[  
{ "a":{ "value":8 , "b":"xxx" }, "c":"zzz" },  
{ "a":{ "value":13 , "b":"yyy"}, "c":"www" }  
]  
}]  
}

The value of the elevel1Array element used in the range facet is determined  
by processing it's level2Array (evaluating b and c fields) and taking  
a.value of the chosen object from level2Array.  
My request looks something like this:

{  
"query": {  
"match\_all": {}  
},  
"facets": {  
"range1": {  
"nested": "level1Array",  
"range": {  
"key\_script": "l2Array = \_source.level1Array.level2Array;  
selectValue(l2Array)",  
"value\_script": "1",  
"ranges": [  
{  
"from": 0,  
"to": 10  
},  
{  
"from": 10,  
"to": 20  
}  
]  
}  
}  
}  
}

The request does work if the facet is not nested and I access the array  
through \_source. My problem is that when the range facet is nested I can  
only access simple level1Array elements with doc['fieldName'].value but  
doc['level1Array.level2Array'].value does not work becasue level2Array is  
object array. I could not access the array through \_source when using  
nested facet. Is there a way to access my level2Array in a script when  
doing nested faceting?

Thanks,  
Gregor

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:48am UTC](https://discuss.elastic.co/t/troubles-accessing-an-object-array-in-a-nested-element-with-a-script/11038/2 "2017-07-06T02:48:03Z")

</div>


