# Nested object scripting

**URL:** <https://discuss.elastic.co/t/nested-object-scripting/16027>\
**Category:** Elasticsearch\
**Created:** [February 26, 2014, 10:53am UTC](https://discuss.elastic.co/t/nested-object-scripting/16027 "2014-02-26T10:53:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mehrez\_Marouani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mehrez_marouani/32/1218_2.png) [@Mehrez\_Marouani](https://discuss.elastic.co/u/Mehrez_Marouani)\
**Post date:** [February 26, 2014, 10:53am UTC](https://discuss.elastic.co/t/nested-object-scripting/16027/1 "2014-02-26T10:53:10Z")

</div>

Hi everyone,

I need to know how to make a facet script for a nested object.

The mapping:

{  
"vehicle": {  
"properties": {  
"id": {  
"type": "long"  
},  
"fitments": {  
"type": "nested",  
"properties": {  
"dimensions": {  
"type": "nested",  
"properties": {  
"id": {  
"type": "long"  
},  
"position": {  
"type": "string",  
"index\_analyzer": "string\_lowercase"  
}  
}  
}  
},  
"id": {  
"type": "long"  
}  
}  
}  
}  
}

I've tried:  
_Query:_  
{  
...  
"facets" : {  
"size" : {  
"terms" : {  
"size" : 15,  
"order" : "term",  
"all\_terms" : false,  
"script" : "\_source.fitments.dimensions.id + ';' +  
\_source.fitments.dimensions.position"  
},  
"nested" : "fitments.dimensions"  
}  
}  
}

_Response:_  
QueryPhaseExecutionException[[en\_us][3]: query[filtered(+(year:[1983 TO  
1983]) +(carMaker:audi) +(carSegment:4000)  
+(carType:base))-\>cache(\_type:vehicle)],from[0],size[0]: Query Failed  
[Failed to execute main query]]; nested: PropertyAccessException[[Error:  
could not access: fitments; in class:  
org.elasticsearch.search.lookup.SourceLookup]\n[Near : {...  
\_source.fitments.dimensions.id ....}]\n ^\n[Line: 1, Column:  
1]];

I've tried also:

_Query:_  
{  
...  
"facets" : {  
"size" : {  
"terms" : {  
"size" : 15,  
"order" : "term",  
"all\_terms" : false,  
"script" : "doc['fitments.dimensions.id'] + ';' +  
doc['fitments.dimensions.position']"  
},  
"nested" : "fitments.dimensions"  
}  
}  
}

_Response:_  
"facets": {  
"size": {  
"\_type": "terms",  
"missing": 0,  
"total": 2,  
"other": 0,  
"terms": [  
{  
"term":  
"org.elasticsearch.index.fielddata.ScriptDocValues$Longs@1b3562af;org.elasticsearch.index.fielddata.ScriptDocValues$Strings@4de1dd1d",  
"count": 2  
}  
]  
}  
}

Thank you in advance for your help guys 🙂

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d735a13a-861c-4d6d-a54d-477be4291e98%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d735a13a-861c-4d6d-a54d-477be4291e98%40googlegroups.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, 1:47am UTC](https://discuss.elastic.co/t/nested-object-scripting/16027/2 "2017-07-06T01:47:16Z")

</div>


