Document Level Security using Regex

Hi all,

I am trying to refine data access to a Role based on regex within Document Level Security. Here a query example:
{
“bool”: {
“must”: {
“match”: {
“field_name”: “name_*”
}
}
}
}

This regex should match all field_name equals to “name_1”, “name_2” etc…

I am worried that it’s not possible to do it on DSL, but i want to be sure that i did not something wrong ?
If not, do you have any idea how to refine access to only these data ?

Thanks a lot,
Julien

Hi Julien,

I think that in your use-case the Wildcard queries are better suited. RegExp is usually used for more complex queries.
https://www.elastic.co/guide/en/elasticsearch/reference/7.x/query-dsl-wildcard-query.html

An example of wildcard query that should work for your use-case:

{
  "wildcard": {
    "field_name": {
      "value": "name_*"
    }
  }
}

In case if you still want to use RegExp, here is an example:
https://www.elastic.co/guide/en/elasticsearch/reference/7.x/query-dsl-regexp-query.html

{
  "regexp": {
    "field_name": {
      "value": "name_.*"
    }
  }
}

Regards,
Dinu

1 Like