Hi,
ES 2.1.1
This post explains that when a nested sub-query is used in conjunction with aggregation on nested fields, that the sub-query needs to be repeated as a filter
in the aggregation.
The documentation also stated that it is possible to have multiple nested sub-queries.
I have a case where a query contains multiple nested sub-queries (on the same nested object) within an overall query including non-nested fields. In boolean terms it looks as follows. History objects are the only nested objects in the mapping.
AND
severity = urgent
OR
AND
company.name = abc
NESTED
AND
history.created_at ≥ 2016-01-01
history.action_name = opened
NESTED
AND
history.created_at ≥ 2015-06-01
history.action_name = closed
The equivalent elastic query is here
My question is how to handle the multiple nested sub-queries in the aggregation clause if I want to aggregate on history.action_name?