Anyway to do a cyclic query? A query within a query


Use case
I have a set of documents, with two fields. In each document an edge is described from Field A to Field B. Thus, a complete Path is described from in document 1 : A(1) to B(2) and document 3 : A(2) to B(4) and document 2 : A(4) to B(6) and so on. (i.e) 1-2-2-4-4-6 and so on.

Possible Solution
I was looking at tracing the relationships using nested aggregations. But once you come down A to B, you can't go to B to A because it will just display reversed results. So, if we can pass results of previous aggregation as a filter to B to A (i.e.) Pick A where A = B from previous result. I don't think there is any aggregation API for this.

Any advice will be welcome.


This is almost like a join, which you cannot do unfortunately.