I have documents like the ones bellow in Elastic. Each document has some information and all mandatory permissions to access the document.
When I query, I would like to pass all user permissions and receive matched documents but am having difficulties with the query.
The documents:
{
"id": 1,
"permissions": ["a", "d"]
}
{
"id": 2,
"permissions": ["a"]
}
{
"id": 3,
"permissions": ["a", "b"]
}
{
"id": 4,
"permissions": ["a", "c"]
}
This is the closest I got:
{
"query": {
"bool": {
"should": [
{
"match_phrase": {
"tags.keyword": "a"
}
},
{
"match_phrase": {
"tags.keyword": "b"
}
},
],
"minimum_should_match": doc.tags.length
}
}
}
// Result are documents with id's 2 and 3.
I tried extending the "minimum_should_match" with the "script" but without success (apparently it does not support it):
"script" : {
"script" : {
"inline": "doc['permissions'].length",
"lang": "painless"
}
}
In an example above, with passed permission array ["a", "b", "c"], the output should be documents with id's 2, 3 and 4. ["a"] matches only document with id 2.
EDIT: Additional information A document has up to 5 permissions, as well as the users, but the set of permissions is quite big (500+), so I am searching for a generic query. The data can also be transformed.
I am using Elastic 7.6 Any help is appreciated!