# Data Masking in elasticsearch

**URL:** https://discuss.elastic.co/t/data-masking-in-elasticsearch/109965
**Category:** Elasticsearch
**Created:** [December 1, 2017, 5:11pm UTC](https://discuss.elastic.co/t/data-masking-in-elasticsearch/109965 "2017-12-01T17:11:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jsbonline2006](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@jsbonline2006](https://discuss.elastic.co/u/jsbonline2006)
#### Post date: [December 1, 2017, 5:11pm UTC](https://discuss.elastic.co/t/data-masking-in-elasticsearch/109965/1 "2017-12-01T17:11:05Z")

</div>

I wanted to know is there any way we can achieve the below usecase from elasticsearch inbuild feature.

I have employee data indexed in elasticsearch search

EMP ID FNAME LNAME COUNTRY Organization Other 50 Attributes associated with Employee

1 Jayesh Bhoyar United States ABC  
2 Tapan pal United States ABC  
3 Ajay United States ABC  
4 Ravi Verma Korea ABC  
7 Pankaj Pal Korea ABC  
5 Sundar Lal Japan ABC  
6 rahul Sri Japan ABC

Now we have 4 users and their access level:

User1 - has access to USA  
User2 - has access to USA, Japan  
User3 - has access to USA, Korea  
User4 - has access to USA, Japan, Korea

User 1

Now when User 1 search ABC he should get 7 results but output should be as follows:

EMP ID FNAME LNAME COUNTRY Organization Other 50 Attributes associated with Employee

1 Jayesh Bhoyar United States ABC  
2 Tapan pal United States ABC  
3 Ajay United States ABC  
XXX XXX XXX Korea XXX XXXXXXXX  
XXX XXX XXX Korea XXX XXXXXXXX  
XXX XXX XXX Japan XXX XXXXXXXX  
XXX XXX XXX Japan XXX XXXXXXXX

**User2**

Now when User 2 search ABC he should get 7 results but output should be as follows:

He should be able to see the Japan results and korean results should be masked

EMP ID FNAME LNAME COUNTRY Organization Other 50 Attributes associated with Employee  
1 Jayesh Bhoyar United States ABC  
2 Tapan pal United States ABC  
3 Ajay United States ABC  
XXX XXX XXX Korea XXX XXXXXXXX  
XXX XXX XXX Korea XXX XXXXXXXX  
5 Sundar Lal Japan ABC  
6 rahul Sri Japan ABC

**User3**  
Now when User 3 search ABC he should get 7 results but output should be as follows:  
He should be able to see the Korean results and Japan results should be masked  
EMP ID FNAME LNAME COUNTRY Organization Other 50 Attributes associated with Employee  
1 Jayesh Bhoyar United States ABC  
2 Tapan pal United States ABC  
3 Ajay United States ABC  
4 Ravi Verma Korea ABC  
7 Pankaj Pal Korea ABC  
XXX XXX XXX Japan XXX XXXXXXXX  
XXX XXX XXX Japan XXX XXXXXXXX

Is there any way we can achieve this by script or span or something else which is inbuild in elasticsearch

---

<div class="post-metadata">

### Author: ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)
#### Post date: [December 3, 2017, 3:03pm UTC](https://discuss.elastic.co/t/data-masking-in-elasticsearch/109965/2 "2017-12-03T15:03:43Z")

</div>

Data masking, just as you exemplified, it is not possible with standard/official plugins, but you can filter out documents based on user access permissions by using [X-Pack Security](https://www.elastic.co/products/x-pack/security)

---

<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: [December 31, 2017, 3:03pm UTC](https://discuss.elastic.co/t/data-masking-in-elasticsearch/109965/3 "2017-12-31T15:03:51Z")

</div>

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