Performing aggregations per child


#1

In my data model, I have users and events performed by those users.

A user is represented by a parent document. The events are child documents.

I would like to do a query where I say, "Find parents who have done event X (ie who have a child of X), and show me (for example) the most common event each parent has done. (ie for each parent look at its children and perform one aggregation per parent)"

Is there any way to do that?


(Mark Walkom) #2

You should be able to do this with https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html

But what sort of agg do you want to do?


#3

Thanks, Mark.

Unless I am mistaken, the has_child filter only gives me the list of parents whose children match a certain set of criteria. I can't THEN say - given this list of parents, for each parent, give me (for example) the number of children each parent has that meet some other criterion? I think I would have to do a separate query for each parent? Or is there a way to do an aggregation on a list of parents' children?

Many thanks


(system) #4