# Encrypt couple of my document fields

**URL:** <https://discuss.elastic.co/t/encrypt-couple-of-my-document-fields/38213>\
**Category:** Elasticsearch\
**Created:** [December 31, 2015, 7:45am UTC](https://discuss.elastic.co/t/encrypt-couple-of-my-document-fields/38213 "2015-12-31T07:45:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tpraizler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tpraizler/32/46271_2.png) [@tpraizler](https://discuss.elastic.co/u/tpraizler)\
**Post date:** [December 31, 2015, 7:45am UTC](https://discuss.elastic.co/t/encrypt-couple-of-my-document-fields/38213/1 "2015-12-31T07:45:10Z")

</div>

Hey,

I am storing some sensitive information in elasticsearch, which I want to be stored encrypted.  
I don't plan to search on those fields, so elasticsearch will just store those fields for me.

Is there a recommended approach to achieve this?  
I need to encrypt the data while indexing, and decrypt when I get the search response.

Thanks!

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [January 4, 2016, 11:01pm UTC](https://discuss.elastic.co/t/encrypt-couple-of-my-document-fields/38213/2 "2016-01-04T23:01:34Z")

</div>

Hi Tomer,

you can solve this almost entirely at the application level in your mapping layer, so before indexing a document, your application encrypts the field and when retrieving a document it decrypts it.

Regarding Elasticsearch, I'd just ensure to store these fields as [not\_analyzed](https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping-intro.html#_index_2), so Elasticsearch indexes the fields as is.

Daniel

---

<div class="post-metadata">

**Author:** ![tpraizler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tpraizler/32/46271_2.png) [@tpraizler](https://discuss.elastic.co/u/tpraizler)\
**Post date:** [January 6, 2016, 2:51pm UTC](https://discuss.elastic.co/t/encrypt-couple-of-my-document-fields/38213/3 "2016-01-06T14:51:52Z")

</div>

Thanks. That's what I thought so.

---

<div class="post-metadata">

**Author:** ![Ramya](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@Ramya](https://discuss.elastic.co/u/Ramya)\
**Post date:** [February 9, 2017, 11:03am UTC](https://discuss.elastic.co/t/encrypt-couple-of-my-document-fields/38213/4 "2017-02-09T11:03:35Z")

</div>

Hi daniel,  
Nice explanation,I want to store my postgres db credential(username and password) in elasticsearch as encrypted format .What I have to do for that? Can u please help me..waiting for ur response..Thanks in advance

---

<div class="post-metadata">

**Author:** ![Ramya](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@Ramya](https://discuss.elastic.co/u/Ramya)\
**Post date:** [February 9, 2017, 1:28pm UTC](https://discuss.elastic.co/t/encrypt-couple-of-my-document-fields/38213/5 "2017-02-09T13:28:20Z")

</div>

Hi Tomer,  
How you store your Sensitive Information in elasticsearch as encrypted and how you decrypt that,Because I too want to store my sensitive data to store as encrypted in Elasticsearch and have to decrypt when search.Eagerly expecting your kind reply..  
Thanks!

---

<div class="post-metadata">

**Author:** ![tpraizler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tpraizler/32/46271_2.png) [@tpraizler](https://discuss.elastic.co/u/tpraizler)\
**Post date:** [March 13, 2017, 9:26am UTC](https://discuss.elastic.co/t/encrypt-couple-of-my-document-fields/38213/6 "2017-03-13T09:26:09Z")

</div>

@Ramya sorry for the delayed response.  
It doesn't sound healthy to store your credentials for one datastore in another datastore.  
take for example the scenario in which datastoreA is not available, that means you can't connect to datastoreB, which doesn't make sense.  
Sensitive credentials should be stored as part of your machine environment, not sure how you run your machines.  
If you have your machines running as part of a cloud service: aws \ heroku \ etc, you get support to how your provide environment variables. if you have your own on-premise machines, you should do it by yourself.

Now, about the encryption, I didn't do it because I didn't want to loose the search functionality (if you encrypt your data, you can't search on it, not using elastic queries at least). I decided to invest more in securing my es using shield.

So if you don't care about your data being searchable, your option as far as I know it, is what @danielmitterdorfer suggested. you should programmatically encrypt \ decrypt your data.

---

<div class="post-metadata">

**Author:** ![Ramya](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@Ramya](https://discuss.elastic.co/u/Ramya)\
**Post date:** [March 15, 2017, 5:56am UTC](https://discuss.elastic.co/t/encrypt-couple-of-my-document-fields/38213/7 "2017-03-15T05:56:43Z")

</div>

@tpraizler  
Thank you so much....for the great explanation

---

<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 5, 2017, 10:02pm UTC](https://discuss.elastic.co/t/encrypt-couple-of-my-document-fields/38213/8 "2017-07-05T22:02:14Z")

</div>


