# Aggregating inner\_hits data

**URL:** <https://discuss.elastic.co/t/aggregating-inner-hits-data/69455>\
**Category:** Elasticsearch\
**Created:** [December 19, 2016, 1:55pm UTC](https://discuss.elastic.co/t/aggregating-inner-hits-data/69455 "2016-12-19T13:55:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohitjain](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@mohitjain](https://discuss.elastic.co/u/mohitjain)\
**Post date:** [December 19, 2016, 1:55pm UTC](https://discuss.elastic.co/t/aggregating-inner-hits-data/69455/1 "2016-12-19T13:55:18Z")

</div>

Hi,

I am naive to Elastic Search. I found there is some problem with array of objects:  
[https://www.elastic.co/guide/en/elasticsearch/guide/current/complex-core-fields.html#object-arrays](https://www.elastic.co/guide/en/elasticsearch/guide/current/complex-core-fields.html#object-arrays)

The solution for this problem given is nested query:  
[https://www.elastic.co/guide/en/elasticsearch/reference/2.2/nested.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.2/nested.html)

I was trying to use this for my use case. Data fomat of my use case:  
"wifi": [  
{  
"point": 1,  
"cha": 14,  
"chb": 2  
},  
{  
"point": 2,  
"cha": 7,  
"chb": 6  
}  
]  
There are many entries like this.  
I used nested query to filter only wifi.point value 1:  
GET my\_index4/\_search  
{  
"\_source" : false,  
"query": {  
"nested": {  
"path": "wifi",  
"query": {  
"bool": {  
"must": [  
{ "match": { "wifi.point": 1 }}  
]  
}  
},  
"inner\_hits": {  
"highlight": {  
}  
}  
}  
}  
}

It displays data inside the inner\_hits for wifi.point 1.  
I need to aggregate this inner\_hits data. How can I do this?

Thanks.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [December 19, 2016, 1:58pm UTC](https://discuss.elastic.co/t/aggregating-inner-hits-data/69455/2 "2016-12-19T13:58:27Z")

</div>

> [@mohitjain](#):
>
> I need to aggregate this inner\_hits data.

See nested aggregations: [Nested Aggregation | Elasticsearch Guide [5.1] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/5.1/search-aggregations-bucket-nested-aggregation.html)

---

<div class="post-metadata">

**Author:** ![mohitjain](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@mohitjain](https://discuss.elastic.co/u/mohitjain)\
**Post date:** [December 20, 2016, 10:42am UTC](https://discuss.elastic.co/t/aggregating-inner-hits-data/69455/3 "2016-12-20T10:42:54Z")

</div>

Hi Mark,

Thanks for the information.  
I did the aggregation on nested data using this:  
GET my\_index4/\_search  
{  
"\_source": false,  
"size": 0,  
"aggs": {  
"wifi": {  
"nested": {  
"path": "wifi"  
},  
"aggs": {  
"only\_point\_name": {  
"filter": {  
"terms": {  
"wifi.point": [  
1,2  
]  
}  
},  
"aggs": {  
"my\_agg\_1": {  
"terms": {  
"field": "wifi.point"  
},  
"aggs": {  
"my\_agg\_2": {  
"sum": {  
"field": "wifi.chb"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
It worked fine. Now I need to allow aggregation on data other than the wifi object like "time" and "Id.Mac".  
Data format:  
{  
"time" : 1477373600000,  
"Id" : {  
"Type" : "NODE",  
"Mac" : "00:06:65:2b:d2:40"  
},  
"wifi" : [{  
"point" : 1,  
"cha" : 14,  
"chb" : 2  
}, {  
"point" : 2,  
"cha" : 7,  
"chb" : 6  
}  
]  
}  
I tried putting these instead of wifi.point in my above GET query but it didn't generate any output.  
How can i do this?

Thanks.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [December 20, 2016, 10:57am UTC](https://discuss.elastic.co/t/aggregating-inner-hits-data/69455/4 "2016-12-20T10:57:07Z")

</div>

Nested aggregations are only to be used on sections of your document that are defined as "nested" in your mapping definition for the index/doctype. The mapping controls if sub-objects in your JSON docs are mapped to "nested" documents in the index or not.

---

<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:** [January 17, 2017, 10:57am UTC](https://discuss.elastic.co/t/aggregating-inner-hits-data/69455/5 "2017-01-17T10:57:17Z")

</div>

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