On my Elasticsearch server I have three indices: Person
, Archive
and Document
.
Each document has a
archive
field which is the_id
of theArchive
it is in.Each archive has a
owner
which is the_id
of thePerson
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:
{
"post_filter": {
"terms": {
"owner": [
"my_owner_id"
]
}
},
"aggs": {
"_filter_archive": {
"filter": {
"terms": {
"owner": [
"my_owner_id"
]
}
},
"aggs": {
"archive": {
"terms": {
"field": "archive"
}
}
}
}
}
}