I have to construct a non-trivial access filter for use with all queries on my document index. My documents and related models look like this:
DocumentIndexModel
- int Id
- List(int) AncestorIdPath
- DocumentAccessModel Access
DocumentAccessModel
- List(Group) Groups
- List(User) Users
Group
- int Id
User
- int Id
The DocumentAccessModel specifies groups and users that have access to the document. Each user can be in several groups. I have implemented a simple access filter requiring a match on one of the following two TermsQueries (NEST):
new TermsQuery
{
Field = Infer.Field(d => d.Access.Groups.First().Id),
Terms = currentUserGroupIds
}
new TermQuery
{
Field = Infer.Field(d => d.Access.Users.First().Id),
Value = currentUser.Id
}
which results in the user correctly only being able to get the documents that have him or one of his groups in the acecss model.
However, and this is the tricky part: I want to expand the filter logic to also require access to all ancestors of the document. In other words, the user should only be able to find the documents that have the user himself or one of his groups in the DocumentAccessModel of the document and each of its ancestors.
To do this, I am considering replacing the DocumentAccessModel on each document with a list of DocumentAccessModels (one for each ancestor of the document), such that access requires that each of these DocumentAccessModels matches either the user directly or one of his groups.
How could such a filter be constructed - and is something like this even possible in elasticsearch?