On my Elasticsearch server I have three indices: Person , Archive and Document .

Each document has a archive field which is the _id of the Archive it is in.

Each archive has a owner which is the _id of the Person that is the owner of the archive.

With the indices above I can aggregate documents into buckets of archives and archives into buckets of owners.

How can I also include the documents in the person aggregations so if I filter on a specific person I get the archives and their documents that belongs to the person instead of only the archives?

This is what I have so far to filter and aggregate the archives into buckets of owners: