Reverse_nested aggregation facing troubles when applied to array of nested objects


(Adrian Luna) #1

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/104ffef4-8bd8-4422-9a19-b3b4a31ff7ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Adrian Luna) #2

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/aed8df74-8e91-4d4f-a0c0-da2f895bf6c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Adrian Luna) #3

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/7d5dce21-abbb-4fa9-b326-9d9e73da4097%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Adrian Luna) #4

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/a1220658-8eca-4b30-b595-3a77b1de8a90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #5