# Any suggestion way of doing soft delete in ES

**URL:** https://discuss.elastic.co/t/any-suggestion-way-of-doing-soft-delete-in-es/139455
**Category:** Elasticsearch
**Created:** [July 11, 2018, 3:20am UTC](https://discuss.elastic.co/t/any-suggestion-way-of-doing-soft-delete-in-es/139455 "2018-07-11T03:20:26Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Lan\_Qi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lan_qi/32/33213_2.png) [@Lan\_Qi](https://discuss.elastic.co/u/Lan_Qi)
#### Post date: [July 11, 2018, 3:20am UTC](https://discuss.elastic.co/t/any-suggestion-way-of-doing-soft-delete-in-es/139455/1 "2018-07-11T03:20:26Z")

</div>

Hi,

I would like to know if there is some official way of doing soft delete in ES?  
Thank you

---

<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: [July 11, 2018, 3:25am UTC](https://discuss.elastic.co/t/any-suggestion-way-of-doing-soft-delete-in-es/139455/2 "2018-07-11T03:25:35Z")

</div>

What do you mean by soft delete?

---

<div class="post-metadata">

### Author: ![Lan\_Qi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lan_qi/32/33213_2.png) [@Lan\_Qi](https://discuss.elastic.co/u/Lan_Qi)
#### Post date: [July 11, 2018, 3:51am UTC](https://discuss.elastic.co/t/any-suggestion-way-of-doing-soft-delete-in-es/139455/3 "2018-07-11T03:51:00Z")

</div>

Not delete directly in storage  
but mark the document somehow to not let it to be searchable  
similar to add a is\_deleted column in mysql

---

<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: [July 11, 2018, 3:58am UTC](https://discuss.elastic.co/t/any-suggestion-way-of-doing-soft-delete-in-es/139455/4 "2018-07-11T03:58:51Z")

</div>

No, there's not.  
If you want it to exist but not be available for search then you should do that during index time.

---

<div class="post-metadata">

### Author: ![Lan\_Qi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lan_qi/32/33213_2.png) [@Lan\_Qi](https://discuss.elastic.co/u/Lan_Qi)
#### Post date: [July 11, 2018, 4:19am UTC](https://discuss.elastic.co/t/any-suggestion-way-of-doing-soft-delete-in-es/139455/5 "2018-07-11T04:19:44Z")

</div>

could you please expand on how to do that during index time?

---

<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: [July 11, 2018, 4:26am UTC](https://discuss.elastic.co/t/any-suggestion-way-of-doing-soft-delete-in-es/139455/6 "2018-07-11T04:26:18Z")

</div>

There's a few ways;  
[https://www.elastic.co/guide/en/elasticsearch/reference/6.3/enabled.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.3/enabled.html)  
[https://www.elastic.co/guide/en/elasticsearch/reference/6.3/mapping-index.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.3/mapping-index.html)

---

<div class="post-metadata">

### Author: ![Lan\_Qi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lan_qi/32/33213_2.png) [@Lan\_Qi](https://discuss.elastic.co/u/Lan_Qi)
#### Post date: [July 11, 2018, 4:53am UTC](https://discuss.elastic.co/t/any-suggestion-way-of-doing-soft-delete-in-es/139455/7 "2018-07-11T04:53:39Z")

</div>

sorry, my question is confusing  
I mean how to hide one document instead of using delete api  
for example, I have 5 docs in the index [doc1, doc2, doc3, doc4, doc5]  
I found doc2 is invalid, so I don't want to it to be searchable in business logic. But to for keeping data for audit purpose, i don't want to delete doc2 directly in ES as well.

I am thinking that to have a field is\_searchable in the doc, and update it to false for doc2, and when search, add a filter is\_searchable = true  
but in this method, i have to update all other existing docs the field to true, but in my real usage, i have millions of existing documents.

In this case, do you any better ideas of doing that?

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [July 11, 2018, 5:11am UTC](https://discuss.elastic.co/t/any-suggestion-way-of-doing-soft-delete-in-es/139455/8 "2018-07-11T05:11:55Z")

</div>

Why not set the field `is_searchable` to `true in all documents at index time and then just update the documents that are to not be visible? You can then access this through a [filtered index alias](https://www.elastic.co/guide/en/elasticsearch/reference/6.3/indices-aliases.html). Note that as the documents are still in the index, they will affect relevancy scoring.

---

<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: [July 11, 2018, 5:26am UTC](https://discuss.elastic.co/t/any-suggestion-way-of-doing-soft-delete-in-es/139455/9 "2018-07-11T05:26:16Z")

</div>

You can also do this with document and field level security - [https://www.elastic.co/guide/en/elastic-stack-overview/6.3/field-and-document-access-control.html](https://www.elastic.co/guide/en/elastic-stack-overview/6.3/field-and-document-access-control.html)

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [July 11, 2018, 5:28am UTC](https://discuss.elastic.co/t/any-suggestion-way-of-doing-soft-delete-in-es/139455/10 "2018-07-11T05:28:54Z")

</div>

Just wondering why do you want this?

---

<div class="post-metadata">

### Author: ![Lan\_Qi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lan_qi/32/33213_2.png) [@Lan\_Qi](https://discuss.elastic.co/u/Lan_Qi)
#### Post date: [July 13, 2018, 3:52am UTC](https://discuss.elastic.co/t/any-suggestion-way-of-doing-soft-delete-in-es/139455/11 "2018-07-13T03:52:21Z")

</div>

no specific reason  
we usually not do hard delete on storage

---

<div class="post-metadata">

### Author: ![Lan\_Qi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lan_qi/32/33213_2.png) [@Lan\_Qi](https://discuss.elastic.co/u/Lan_Qi)
#### Post date: [July 13, 2018, 3:54am UTC](https://discuss.elastic.co/t/any-suggestion-way-of-doing-soft-delete-in-es/139455/12 "2018-07-13T03:54:28Z")

</div>

thank you for your suggestion

yes we will set is\_searchable to true for new document at index time

the problem is updating all existing 60 millions data is not ideal

actually, considering the indexed doc will affect scoring on search, i am hesitate on doing this now

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [July 13, 2018, 5:51am UTC](https://discuss.elastic.co/t/any-suggestion-way-of-doing-soft-delete-in-es/139455/13 "2018-07-13T05:51:01Z")

</div>

So don't complicate things IMHO.

---

<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: [August 10, 2018, 5:51am UTC](https://discuss.elastic.co/t/any-suggestion-way-of-doing-soft-delete-in-es/139455/14 "2018-08-10T05:51:17Z")

</div>

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