# Nested aggregation problem

**URL:** <https://discuss.elastic.co/t/nested-aggregation-problem/27090>\
**Category:** Elasticsearch\
**Created:** [August 9, 2015, 3:57pm UTC](https://discuss.elastic.co/t/nested-aggregation-problem/27090 "2015-08-09T15:57:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thamizharasu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thamizharasu/32/4112_2.png) [@Thamizharasu](https://discuss.elastic.co/u/Thamizharasu)\
**Post date:** [August 9, 2015, 3:57pm UTC](https://discuss.elastic.co/t/nested-aggregation-problem/27090/1 "2015-08-09T15:57:01Z")

</div>

I am facing some problem with nested Aggregation. I am NOT able to get any aggregation result. I have added my JSON index values and aggregation query. Please help me to resolve this problem.

JSON output:  
{  
"took": 1,  
"timed\_out": false,  
"\_shards":  
{  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits":  
{  
"total": 1,  
"max\_score": 1,  
"hits":  
[  
{  
"\_index": "talks",  
"\_type": "ftype",  
"\_id": "84d81284-ceaf-408d-8fe4-3bd3a633e5db",  
"\_score": 1,  
"\_source":  
{  
"id": "84d81284-ceaf-408d-8fe4-3bd3a633e5db",  
"questId": "7da5a2f4-052a-4d09-befb-a657b39bc4fc",  
"user":  
{  
"id": "cf61d4ac-0374-4cac-a4df-e504b7c18868",  
"name": "Roger",  
"email": "roger@gmail.com",  
"mobile": null,  
"dob": null  
},  
"opinions":  
[  
{  
"title": "Do you like our service?",  
"labels":  
[  
"service"  
],  
"rating": "OK"  
},  
{  
"title": "Do you refer to your friend?",  
"labels":  
[  
"reference"  
],  
"rating": "OK"  
},  
{  
"title": "Do you like our ambiance?",  
"labels":  
[  
"ambiance"  
],  
"rating": "NO"  
}  
],  
"date": null  
}  
}  
]  
}  
}

Aggregation query:  
{  
"aggs" : {  
"ratings" : {  
"terms" : {  
"field" : "opinions.rating"  
}  
}  
}  
}

Aggregation result:  
{  
"took": 110,  
"timed\_out": false,  
"\_shards":  
{  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits":  
{  
"total": 1,  
"max\_score": 0,  
"hits":  
[  
]  
},  
"aggregations":  
{  
"ratings":  
{  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets":  
[  
{  
"key": "no",  
"doc\_count": 1  
},  
{  
"key": "ok",  
"doc\_count": 1  
}  
]  
}  
}  
}

Even I changed my query with "nested" type, I am NOT able to get any result. Please help me...

---

<div class="post-metadata">

**Author:** ![Thamizharasu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thamizharasu/32/4112_2.png) [@Thamizharasu](https://discuss.elastic.co/u/Thamizharasu)\
**Post date:** [December 15, 2015, 12:12pm UTC](https://discuss.elastic.co/t/nested-aggregation-problem/27090/2 "2015-12-15T12:12:21Z")

</div>

I solved the problem by changing the mapping configuration with proper sub type.

---

<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 5, 2017, 11:30pm UTC](https://discuss.elastic.co/t/nested-aggregation-problem/27090/3 "2017-07-05T23:30:57Z")

</div>


