How to find all parents where child property exist

Hi All ,
I am trying to solve a reverse query problem and reaching out to find the best possible way.
I have an existing index which contains

A : [1,2,3,4]
B : [2,3]
C : [3,5,6] .....

10000 entries
Parent is A , B ,C that contains child array of objects 1,2,3,4,5,6...
I need to find which all parents where a child exist as list in a rest call to elastic.

1 : [A]
2: [A ,B]
3: [A,B,C]

Can you provide a full reproducible example including index creation and document creation. This way the mental model of everyone reading this will be much better and it will be easier to find a solution (are you using nested/ parent-child, which is the parent and the child etc is nothing we need to assume but know for a given!)

Thank you!

PUT /team

PUT team/_doc/A
{  "fans" : [ {"id": 1} ,{"id":2 }, {"id" :3}] }

PUT team/_doc/B
{  "fans" :  [ {"id": 2} ,{"id": 3 }]}

PUT team/_doc/C
{  "fans" :  [ {"id": 3} ,{"id":4 }, {"id" :5 }] }

Need to find out , fan ID : 1 follows how many teams , similarly for fan ID 2,3,5,6
Expected result :
1 : [A], 2: [A,B] , 3 : [B,C]

you could change your data structure to fans: ["1", "2", "3"] by omitting the id.. now you can use a terms aggregation, or just run a query to search for fans: 1 and count the number of results?

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