Reverse nested query for filter in aggregations required

Let's assume I have a document A with fields a and b, b is a list of nested documents B with fields b1 and b2
Now set up some documents for A:

{a:1, b:[{b1:1, b2:1}, {b1:2, b2:2}] }
{a:2, b:[{b1:3, b2:1}, {b1:4, b2:2}] }

What I need: all different values for b1 where b2 == 1 OR a == 1; i.e. 1,2,3

This has to be done in a nested aggregation; and we need a filter, and inside the filter a terms aggregation on b1.
The filter will be a boolQuery with 2 should statements and a minimum match of 1. So far, it's still okay.
My problem:

  • If I create the filter on the outer level (as aggregation or query), both objects match, and the nested terms aggregation would return 1,2,3,4
  • If I filter only for b2 in the nested aggregation, I would get 1 and 3
  • I need a reverse nested query inside the bool query of the nested filter aggregation, but it seems as if this does not exist.

Any ideas? Is there a solution?
As far as I am aware of, this would require a reverse nested query - which is currently not implemented. Are there plans to do so?

Is there a special reason why this is not supported?
Are there plans to provide a solution for this? In 5.x? 6.x?

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