3

In ElasticSearch I have the following document structure...

{
    name: "bob",
    permissions: [
        2,
        4,
        6
    ]
}

I need to be able to perform a search which will check if the permissions for "bob" are contained within a given array.

e.g I have an array with contents

[1,2,3,4,5,6]

I need the "bob" document to be returned because my array contains 2,4,6 and so does "bob"

If my array contained 1,3,4,5,6 "bob" should not be selected because my array does not contain "2"

Essentially I want to match any documents whose permission entries are all contained in my array.

1 Answer 1

2

Your use case is, basically, "for a set of permissions (which a particular user has), find all the documents that only require permissions in that set."

One solution would be to provide an implementation which does "for a set of permissions, find all the documents which don't require any other permission."

Provided all possible values for permission can be retrieved at any time*, you can get that list, remove the values possessed by the current user, and put each of the remaining values in a "must_not" term of a bool filter.

Even for a large number of possible permissions, the search operation would be quite fast, as those term filters would be cached.

*If no other method of finding all possible values of permission is reliable, you could do a terms aggregation on permission to find all currently indexed values.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.