# Using \_user.Roles in role template

**URL:** <https://discuss.elastic.co/t/using-user-roles-in-role-template/115326>\
**Category:** Elasticsearch\
**Created:** [January 12, 2018, 3:47pm UTC](https://discuss.elastic.co/t/using-user-roles-in-role-template/115326 "2018-01-12T15:47:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jchannon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jchannon/32/23280_2.png) [@jchannon](https://discuss.elastic.co/u/jchannon)\
**Post date:** [January 12, 2018, 3:47pm UTC](https://discuss.elastic.co/t/using-user-roles-in-role-template/115326/1 "2018-01-12T15:47:41Z")

</div>

I have the below query template in my role:

`{"template":{"source":{"match":{"role.keyword","{{_user.roles}}"}}}}`

`role` in that example is an array on a document. `_user.roles` is obviously an array.

When I log in as a user I see `Discover: [script] failed to parse field [source]` in Kibana which I assume to be an issue with the above template. Is what I'm trying to achieve possible which is the document can only be visible if one of the user roles matches any of the roles property on the document

---

<div class="post-metadata">

**Author:** ![jchannon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jchannon/32/23280_2.png) [@jchannon](https://discuss.elastic.co/u/jchannon)\
**Post date:** [January 12, 2018, 5:23pm UTC](https://discuss.elastic.co/t/using-user-roles-in-role-template/115326/2 "2018-01-12T17:23:31Z")

</div>

I don't know if this addresses it? [https://www.elastic.co/blog/attribute-based-access-control-with-xpack](https://www.elastic.co/blog/attribute-based-access-control-with-xpack?blade=tw&hulk=social)

---

<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:** [February 9, 2018, 5:23pm UTC](https://discuss.elastic.co/t/using-user-roles-in-role-template/115326/3 "2018-02-09T17:23:32Z")

</div>

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