# Field level security based on the value of another field in the document

**URL:** https://discuss.elastic.co/t/field-level-security-based-on-the-value-of-another-field-in-the-document/315356
**Category:** Elasticsearch
**Tags:** elastic-stack-security
**Created:** [September 28, 2022, 10:34am UTC](https://discuss.elastic.co/t/field-level-security-based-on-the-value-of-another-field-in-the-document/315356 "2022-09-28T10:34:26Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Ram\_Rana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ram_rana/32/97440_2.png) [@Ram\_Rana](https://discuss.elastic.co/u/Ram_Rana)
#### Post date: [September 28, 2022, 10:34am UTC](https://discuss.elastic.co/t/field-level-security-based-on-the-value-of-another-field-in-the-document/315356/1 "2022-09-28T10:34:26Z")

</div>

We have one use case where we need to put some field level security based on another field in the document.  
We have some documents, each document contain one field called type and based on that type we want to put restrictions on few other fields which can be retrieved or not by the user.  
Is this possible ?

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [October 4, 2022, 5:21am UTC](https://discuss.elastic.co/t/field-level-security-based-on-the-value-of-another-field-in-the-document/315356/2 "2022-10-04T05:21:31Z")

</div>

Welcome to our community! 😃

As far as I know you can do this via [document level security](https://www.elastic.co/guide/en/elasticsearch/reference/8.4/document-level-security.html) but not on field level in the same way.

---

<div class="post-metadata">

### Author: ![Ram\_Rana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ram_rana/32/97440_2.png) [@Ram\_Rana](https://discuss.elastic.co/u/Ram_Rana)
#### Post date: [October 4, 2022, 5:36am UTC](https://discuss.elastic.co/t/field-level-security-based-on-the-value-of-another-field-in-the-document/315356/3 "2022-10-04T05:36:17Z")

</div>

Thank you for answering.  
One way to achieve this is by separating the documents by creating different indices, apart from this do you see any other alternative ?

---

<div class="post-metadata">

### Author: ![Yang\_Wang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yang_wang/32/48857_2.png) [@Yang\_Wang](https://discuss.elastic.co/u/Yang_Wang)
#### Post date: [October 4, 2022, 5:37am UTC](https://discuss.elastic.co/t/field-level-security-based-on-the-value-of-another-field-in-the-document/315356/4 "2022-10-04T05:37:39Z")

</div>

This is not possible today. The closest thing you can get is to grant different access based on user's attribute with either [Role mapping templates](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-put-role-mapping.html#_role_templates) or [DLS templated role query](https://www.elastic.co/guide/en/elasticsearch/reference/current/field-and-document-access-control.html#templating-role-query) or both.

Or just split documents into multiple indices. This is what I'd recommend.

---

<div class="post-metadata">

### Author: ![Ram\_Rana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ram_rana/32/97440_2.png) [@Ram\_Rana](https://discuss.elastic.co/u/Ram_Rana)
#### Post date: [October 4, 2022, 5:58am UTC](https://discuss.elastic.co/t/field-level-security-based-on-the-value-of-another-field-in-the-document/315356/5 "2022-10-04T05:58:46Z")

</div>

Yes, I also explored these options but I was thinking if there is any other alternative.  
Splitting the index is fine but the thing is we don't know if we get more scenarios like this, so this would not be the perfect solution to split the indices many times.

Thank you so much for answering, it would be great if we get something to handle the given scenario soon.

---

<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: [November 1, 2022, 5:59am UTC](https://discuss.elastic.co/t/field-level-security-based-on-the-value-of-another-field-in-the-document/315356/6 "2022-11-01T05:59:19Z")

</div>

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