Filter in nested aggregations

Hi all,

I was wondering if it is possible to apply aggregations only on a set of
nested objects (not all nested objects presents inside a document),
according to a property of this object? I think an example will help to
understand.

Let's say that you have the following documents inthe index:

{
"a": 2,
"b": 3,
"c": 4,
"d": [
{
"toto": 1,
"tutu": 2,
"titi": 3
},
{
"toto": 2,
"tutu": 5,
"titi": 6
},
{
"toto": 3,
"tutu": 11,
"titi": 8
},
{
"toto": 4,
"tutu": 7,
"titi": 4
}
]
}

{
"a": 3,
"b": 4,
"c": 5,
"d": [
{
"toto": 1,
"tutu": 10,
"titi": 6
},
{
"toto": 2,
"tutu": 65,
"titi": 8
},
{
"toto": 3,
"tutu": 25,
"titi": 15
},
{
"toto": 4,
"tutu": 30,
"titi": 45
}
]
}

Where "d" is indexed as nested. I would like to get the maximum value for
the "tutu" property from this kind of documents, but I would like to work
only on nested objects where "toto" = 1. Here, I would like to get 10 (the
red one in the samples), and not 65.

Is it possible to do this kind of aggregation? Or have I to change my
document structure (or index mapping or ...)? If it is possible, could you
point me how to do it? I had a look at nested aggregations and filter ones,
but I am not sure that it could help.

Thank you for your replies.

Regards,
Loïc

--
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/681f7e7f-6340-4699-88f4-bb99032e47b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Provided that d is mapped as a nested object, you can do it by using
the nested aggregation. Here are the aggregations that you would need on
each level

  1. nested aggregation to be in the context of path='d'
  2. filter aggregation on d.toto == 1
  3. max aggregation on d.tutu

On Wed, Jan 14, 2015 at 11:08 AM, Loïc Wenkin loic.wenkin@gmail.com wrote:

Hi all,

I was wondering if it is possible to apply aggregations only on a set of
nested objects (not all nested objects presents inside a document),
according to a property of this object? I think an example will help to
understand.

Let's say that you have the following documents inthe index:

{
"a": 2,
"b": 3,
"c": 4,
"d": [
{
"toto": 1,
"tutu": 2,
"titi": 3
},
{
"toto": 2,
"tutu": 5,
"titi": 6
},
{
"toto": 3,
"tutu": 11,
"titi": 8
},
{
"toto": 4,
"tutu": 7,
"titi": 4
}
]
}

{
"a": 3,
"b": 4,
"c": 5,
"d": [
{
"toto": 1,
"tutu": 10,
"titi": 6
},
{
"toto": 2,
"tutu": 65,
"titi": 8
},
{
"toto": 3,
"tutu": 25,
"titi": 15
},
{
"toto": 4,
"tutu": 30,
"titi": 45
}
]
}

Where "d" is indexed as nested. I would like to get the maximum value for
the "tutu" property from this kind of documents, but I would like to work
only on nested objects where "toto" = 1. Here, I would like to get 10
(the red one in the samples), and not 65.

Is it possible to do this kind of aggregation? Or have I to change my
document structure (or index mapping or ...)? If it is possible, could you
point me how to do it? I had a look at nested aggregations and filter ones,
but I am not sure that it could help.

Thank you for your replies.

Regards,
Loïc

--
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/681f7e7f-6340-4699-88f4-bb99032e47b5%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/681f7e7f-6340-4699-88f4-bb99032e47b5%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
Adrien Grand

--
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/CAL6Z4j6mCs-gBR8fOygLEcX98JUVxgqg2d%2B-3_V_6SBOuq3iRA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Hi Adrien,

Thanks a lot, it works!

Regards,
Loïc

Le mercredi 14 janvier 2015 12:06:54 UTC+1, Adrien Grand a écrit :

Provided that d is mapped as a nested object, you can do it by using
the nested aggregation. Here are the aggregations that you would need on
each level

  1. nested aggregation to be in the context of path='d'
  2. filter aggregation on d.toto == 1
  3. max aggregation on d.tutu

On Wed, Jan 14, 2015 at 11:08 AM, Loïc Wenkin <loic....@gmail.com
<javascript:>> wrote:

Hi all,

I was wondering if it is possible to apply aggregations only on a set of
nested objects (not all nested objects presents inside a document),
according to a property of this object? I think an example will help to
understand.

Let's say that you have the following documents inthe index:

{
"a": 2,
"b": 3,
"c": 4,
"d": [
{
"toto": 1,
"tutu": 2,
"titi": 3
},
{
"toto": 2,
"tutu": 5,
"titi": 6
},
{
"toto": 3,
"tutu": 11,
"titi": 8
},
{
"toto": 4,
"tutu": 7,
"titi": 4
}
]
}

{
"a": 3,
"b": 4,
"c": 5,
"d": [
{
"toto": 1,
"tutu": 10,
"titi": 6
},
{
"toto": 2,
"tutu": 65,
"titi": 8
},
{
"toto": 3,
"tutu": 25,
"titi": 15
},
{
"toto": 4,
"tutu": 30,
"titi": 45
}
]
}

Where "d" is indexed as nested. I would like to get the maximum value for
the "tutu" property from this kind of documents, but I would like to work
only on nested objects where "toto" = 1. Here, I would like to get 10
(the red one in the samples), and not 65.

Is it possible to do this kind of aggregation? Or have I to change my
document structure (or index mapping or ...)? If it is possible, could you
point me how to do it? I had a look at nested aggregations and filter ones,
but I am not sure that it could help.

Thank you for your replies.

Regards,
Loïc

--
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 elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/681f7e7f-6340-4699-88f4-bb99032e47b5%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/681f7e7f-6340-4699-88f4-bb99032e47b5%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
Adrien Grand

--
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/9fecd1ff-4d6b-4d24-acd0-c7e6e457abc0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.