# Reverse\_nested aggregation facing troubles when applied to array of nested objects

**URL:** <https://discuss.elastic.co/t/reverse-nested-aggregation-facing-troubles-when-applied-to-array-of-nested-objects/18153>\
**Category:** Elasticsearch\
**Created:** [June 17, 2014, 12:18pm UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-facing-troubles-when-applied-to-array-of-nested-objects/18153 "2014-06-17T12:18:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrian\_Luna](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Adrian\_Luna](https://discuss.elastic.co/u/Adrian_Luna)\
**Post date:** [June 17, 2014, 12:18pm UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-facing-troubles-when-applied-to-array-of-nested-objects/18153/1 "2014-06-17T12:18:08Z")

</div>

I have an issue where my mapping includes an array of nested objects. Let's  
imagine something simplified like this:

{  
"properties":{  
"datetime":{"type":"date"},  
"tags":{"type":"object","properties":{

"object\_of\_type\_a":{"type":"nested","properties":{"##SOME FIELDS##"}},

"object\_of\_type\_b":{"type":"nested","properties":{"##SOME FIELDS##"}},  
}  
}  
}

Both object\_of\_type\_a and object\_of\_type\_b are arrays of the actual nested  
object.

So, one doc may look like:

{  
"datetime":"17-06-2014T14:11",  
"##other fields I don't care about right now##",  
"tags":{  
"object\_of\_type\_a":[{"form":"whatever",...},{"form":"another thing",...}],  
"object\_of\_type\_b":[{"form":"something else",...},{"form":"others",...}],  
}  
}

Now imagine I want to aggregate for each element of some of the fields from  
one of the inner objects, but also obtain their histogram based on the  
top-level field ("datetime").

"aggs": {  
"top\_agg": {  
"nested": {  
"path": "tags.object\_of\_type\_a"  
},  
"aggs": {  
"medium\_agg": {  
"terms": {  
"size": 5,  
"field": "tags.object\_of\_type\_a.form"  
},  
"aggs": {  
"reverse": {  
"reverse\_nested": {},  
"aggs": {  
"timeline": {  
"date\_histogram": {  
"field": "datetime",  
"interval": "day"  
}  
}  
}  
}  
}  
}  
}  
}

Once I try to do so, I am getting an error:

Parse Failure [Aggregation definition for [object\_of\_type\_a starts with a  
[START\_ARRAY], expected a [START\_OBJECT].]]; }

Is it possible to perform such an aggregation?  
Thanks in advance. Really appreciate any help you can provide..

--  
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/104ffef4-8bd8-4422-9a19-b3b4a31ff7ec%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/104ffef4-8bd8-4422-9a19-b3b4a31ff7ec%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Adrian\_Luna](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Adrian\_Luna](https://discuss.elastic.co/u/Adrian_Luna)\
**Post date:** [June 17, 2014, 1:11pm UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-facing-troubles-when-applied-to-array-of-nested-objects/18153/2 "2014-06-17T13:11:25Z")

</div>

Ok, just realized something. The problem wasn't related to this. But in  
order to use the 1.2 version (which first expose this reverse\_nested  
functionallity), something seem to change from the 1.1 version I was using  
before.

Something I usually did before is aggregation by several fields using the  
same aggregation name in order to "merge" the results (which I must  
recognize, I have never seen documented). I mean:

{  
"aggs":{  
"forms":[  
{"terms":{"field":"object\_of\_type\_a.form"}},  
{"terms":{"field":"object\_of\_type\_b.form"}}  
]  
}  
}

Such thing was working on previous versions, but not anymore?

Thanks in advance

El martes, 17 de junio de 2014 14:18:08 UTC+2, Adrian Luna escribió:

> I have an issue where my mapping includes an array of nested objects.  
> Let's imagine something simplified like this:
> 
> ....

--  
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/aed8df74-8e91-4d4f-a0c0-da2f895bf6c3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/aed8df74-8e91-4d4f-a0c0-da2f895bf6c3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Adrian\_Luna](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Adrian\_Luna](https://discuss.elastic.co/u/Adrian_Luna)\
**Post date:** [June 17, 2014, 1:25pm UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-facing-troubles-when-applied-to-array-of-nested-objects/18153/3 "2014-06-17T13:25:55Z")

</div>

If not possible. Is there any other way to aggregate by several fields?

El martes, 17 de junio de 2014 15:11:26 UTC+2, Adrian Luna escribió:

> Ok, just realized something. The problem wasn't related to this. But in  
> order to use the 1.2 version (which first expose this reverse\_nested  
> functionallity), something seem to change from the 1.1 version I was using  
> before.
> 
> Something I usually did before is aggregation by several fields using the  
> same aggregation name in order to "merge" the results (which I must  
> recognize, I have never seen documented). I mean:
> 
> {  
> "aggs":{  
> "forms":[  
> {"terms":{"field":"object\_of\_type\_a.form"}},  
> {"terms":{"field":"object\_of\_type\_b.form"}}  
> ]  
> }  
> }
> 
> Such thing was working on previous versions, but not anymore?
> 
> Thanks in advance
> 
> El martes, 17 de junio de 2014 14:18:08 UTC+2, Adrian Luna escribió:
> 
> > I have an issue where my mapping includes an array of nested objects.  
> > Let's imagine something simplified like this:
> > 
> > ....

--  
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/7d5dce21-abbb-4fa9-b326-9d9e73da4097%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7d5dce21-abbb-4fa9-b326-9d9e73da4097%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Adrian\_Luna](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Adrian\_Luna](https://discuss.elastic.co/u/Adrian_Luna)\
**Post date:** [June 17, 2014, 1:27pm UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-facing-troubles-when-applied-to-array-of-nested-objects/18153/4 "2014-06-17T13:27:46Z")

</div>

If not possible. Is there any other way to aggregate by several fields? Or  
do I need to make 2 different aggregations and then merge them in my  
application?

El martes, 17 de junio de 2014 15:11:26 UTC+2, Adrian Luna escribió:

> Ok, just realized something. The problem wasn't related to this. But in  
> order to use the 1.2 version (which first expose this reverse\_nested  
> functionallity), something seem to change from the 1.1 version I was using  
> before.
> 
> Something I usually did before is aggregation by several fields using the  
> same aggregation name in order to "merge" the results (which I must  
> recognize, I have never seen documented). I mean:
> 
> {  
> "aggs":{  
> "forms":[  
> {"terms":{"field":"object\_of\_type\_a.form"}},  
> {"terms":{"field":"object\_of\_type\_b.form"}}  
> ]  
> }  
> }
> 
> Such thing was working on previous versions, but not anymore?
> 
> Thanks in advance
> 
> El martes, 17 de junio de 2014 14:18:08 UTC+2, Adrian Luna escribió:
> 
> > I have an issue where my mapping includes an array of nested objects.  
> > Let's imagine something simplified like this:
> > 
> > ....

--  
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/a1220658-8eca-4b30-b595-3a77b1de8a90%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a1220658-8eca-4b30-b595-3a77b1de8a90%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:21am UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-facing-troubles-when-applied-to-array-of-nested-objects/18153/5 "2017-07-06T01:21:51Z")

</div>


