# Apply filter from the \_user variable

**URL:** https://discuss.elastic.co/t/apply-filter-from-the-user-variable/236356
**Category:** Kibana
**Created:** [June 9, 2020, 2:08pm UTC](https://discuss.elastic.co/t/apply-filter-from-the-user-variable/236356 "2020-06-09T14:08:41Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Felix\_Valembois](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felix_valembois/32/69981_2.png) [@Felix\_Valembois](https://discuss.elastic.co/u/Felix_Valembois)
#### Post date: [June 9, 2020, 2:08pm UTC](https://discuss.elastic.co/t/apply-filter-from-the-user-variable/236356/1 "2020-06-09T14:08:41Z")

</div>

Hello,

My problem is this : I want to filter the data in kibana in function of the name of the user connected (and other restriction that goes with the user.)

So far, I applied a restriction on document with a query thanks to the document level security (x-pack with platinium version)

And i would like to add in my query a condition due to the user name. With this following documentation :  
[https://www.elastic.co/guide/en/elasticsearch/reference/7.x/field-and-document-access-control.html#templating-role-query](https://www.elastic.co/guide/en/elasticsearch/reference/7.x/field-and-document-access-control.html#templating-role-query)  
I suppose it is workable, but i can't figure out a way to merge my query with the user restriction.

my current query :

```auto
{
   "bool":{
      "must":[
         {
            "bool":{
               "should":[
                  {
                     "match":{
                        "TypeEve":"FAC"
                     }
                  },
                  {
                     "match":{
                        "Coloris":"BLEU "
                     }
                  },
                  {
                     "match":{
                        "Coloris":"VERT "
                     }
                  }
               ],
               "minimum_should_match":2
            }
         }
      ]
   }
}

```

I would like to add :

```auto
 "match":{
                        "Name":"{{_user.username}}"
}

```

but it seems to work in a different way

I hope my problem is clear enough, can someone help me please ? 😄

---

<div class="post-metadata">

### Author: ![mikecote](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikecote/32/58549_2.png) [@mikecote](https://discuss.elastic.co/u/mikecote)
#### Post date: [June 10, 2020, 6:24pm UTC](https://discuss.elastic.co/t/apply-filter-from-the-user-variable/236356/2 "2020-06-10T18:24:46Z")

</div>

Hi @Felix_Valembois,

The `_user` variable is specific to document level security and not accessible elsewhere. To get this working, you will need to make sure the user and the restriction belong to the same role and the filtering should then be done automatically by Elasticsearch.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 8, 2020, 6:24pm UTC](https://discuss.elastic.co/t/apply-filter-from-the-user-variable/236356/3 "2020-07-08T18:24:47Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
