I have a unique query use case that I can't seem to find covered in the documentation. (I'm using ElasticSearch 7.17)
I have documents inside an index that are shaped the following way:
{
parentName: string
children: [
{ name: string },
{ name: string },
]
}
Each document can have an array of children ranging from size 0 to N (any number). Due to a data discrepancy, I need to do the following with a query:
- Get a list of
parentName
values from all documents that only have 1 child - Use this list inside a query to pull all documents that have more than 1 child AND contain a child whose name is equal to some
parentName
inside the list
Is this possible to do from one query? (Or perhaps there is a way to do this with scripts?)
So far I've succeeded in using an query
and aggregation
to achieve step one, but I don't understand how I can use the aggregation result in a following query
Thanks for any help