# Nested object aggs query

**URL:** <https://discuss.elastic.co/t/nested-object-aggs-query/147483>\
**Category:** Elasticsearch\
**Created:** [September 6, 2018, 2:22am UTC](https://discuss.elastic.co/t/nested-object-aggs-query/147483 "2018-09-06T02:22:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shuai\_Yan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shuai_yan/32/35233_2.png) [@Shuai\_Yan](https://discuss.elastic.co/u/Shuai_Yan)\
**Post date:** [September 6, 2018, 2:22am UTC](https://discuss.elastic.co/t/nested-object-aggs-query/147483/1 "2018-09-06T02:22:20Z")

</div>

Hi, I have one index which has document as follows:  
{  
"\_index": "issue\_index\_v1",  
"\_type": "issue",  
"\_id": "830275",  
"\_score": null,  
"\_source": {  
"id": 830275,  
"projectCustom2159": {  
"customField832": 3  
}  
},  
"sort": [  
"3"  
]  
},  
...  
{  
"\_index": "issue\_index\_v1",  
"\_type": "issue",  
"\_id": "830058",  
"\_score": null,  
"\_source": {  
"id": 830058,  
"projectCustom2159": {  
"customField832": 4  
}  
},  
"sort": [  
"4"  
]  
},  
{  
"\_index": "issue\_index\_v1",  
"\_type": "issue",  
"\_id": "830072",  
"\_score": null,  
"\_source": {  
"id": 830072,  
"projectCustom2159": {  
"customField832": 4  
}  
},  
"sort": [  
"4"  
]  
},  
{  
"\_index": "issue\_index\_v1",  
"\_type": "issue",  
"\_id": "830170",  
"\_score": null,  
"\_source": {  
"id": 830170,  
"projectCustom2159": {  
"customField832": 4  
}  
},  
"sort": [  
"4"  
]  
},  
{  
"\_index": "issue\_index\_v1",  
"\_type": "issue",  
"\_id": "830266",  
"\_score": null,  
"\_source": {  
"id": 830266,  
"projectCustom2159": {  
"customField832": 4  
}  
},  
"sort": [  
"4"  
]  
},  
{  
"\_index": "issue\_index\_v1",  
"\_type": "issue",  
"\_id": "830104",  
"\_score": null,  
"\_source": {  
"id": 830104,  
"projectCustom2159": {  
"customField832": 4  
}  
},  
"sort": [  
"4"  
]  
},  
{  
"\_index": "issue\_index\_v1",  
"\_type": "issue",  
"\_id": "830987",  
"\_score": null,  
"\_source": {  
"id": 830987,  
"projectCustom2159": {  
"customField832": 5  
}  
},  
"sort": [  
"5"  
]  
},  
{  
"\_index": "issue\_index\_v1",  
"\_type": "issue",  
"\_id": "830990",  
"\_score": null,  
"\_source": {  
"id": 830990,  
"projectCustom2159": {  
"customField832": 5  
}  
},  
"sort": [  
"5"  
]  
},  
{  
"\_index": "issue\_index\_v1",  
"\_type": "issue",  
"\_id": "831022",  
"\_score": null,  
"\_source": {  
"id": 831022,  
"projectCustom2159": {  
"customField832": 5  
}  
},  
"sort": [  
"5"  
]  
},  
{  
"\_index": "issue\_index\_v1",  
"\_type": "issue",  
"\_id": "830985",  
"\_score": null,  
"\_source": {  
"id": 830985,  
"projectCustom2159": {  
"customField832": 5  
}  
},  
"sort": [  
"5"  
]  
},  
{  
"\_index": "issue\_index\_v1",  
"\_type": "issue",  
"\_id": "830518",  
"\_score": null,  
"\_source": {  
"id": 830518  
},  
"sort": [  
null  
]  
},  
{  
"\_index": "issue\_index\_v1",  
"\_type": "issue",  
"\_id": "830329",  
"\_score": null,  
"\_source": {  
"id": 830329  
},  
"sort": [  
null  
]  
}

Now I wan't to query value count aggs on projectCustom2159.customField832, I wrote the query as follows:  
{"aggs":{"projectCustom2159":{"aggs":{"customField832":{"aggs":{"1":{"aggs":{"2":{"value\_count":{"field":"id"}}},"reverse\_nested":{}}},"terms":{"field":"projectCustom2159.customField832","size":10000,"order":{"\_term":"asc"},"missing":"-2147483648"}}},"nested":{"path":"projectCustom2159"}}},"sort":{"projectCustom2159.customField832":{"order":"asc","mode":"max","nested\_path":"projectCustom2159"}},"\_source":{"includes":[],"excludes":["description"]},"from":0,"query":{"bool":{"filter":[]}},"size":10000}

the result shows:  
"aggregations": {  
"projectCustom2159": {  
"doc\_count": 16,  
"customField832": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets": [  
{  
"1": {  
"2": {  
"value": 4  
},  
"doc\_count": 4  
},  
"key": "3",  
"doc\_count": 4  
},  
....  
}  
}  
}

Indeed, I want

---

<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:** [October 4, 2018, 2:22am UTC](https://discuss.elastic.co/t/nested-object-aggs-query/147483/2 "2018-10-04T02:22:27Z")

</div>

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