# Delete or update empty value, which is more efficient in ES?

**URL:** https://discuss.elastic.co/t/delete-or-update-empty-value-which-is-more-efficient-in-es/40595
**Category:** Elasticsearch
**Created:** [February 1, 2016, 3:34am UTC](https://discuss.elastic.co/t/delete-or-update-empty-value-which-is-more-efficient-in-es/40595 "2016-02-01T03:34:33Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Gary\_Wu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gary_wu/32/4834_2.png) [@Gary\_Wu](https://discuss.elastic.co/u/Gary_Wu)
#### Post date: [February 1, 2016, 3:34am UTC](https://discuss.elastic.co/t/delete-or-update-empty-value-which-is-more-efficient-in-es/40595/1 "2016-02-01T03:34:33Z")

</div>

Hi  
I use ES in a cluster, and the system is very busy. if the ES cluster receives many delete messages in a short time, could these messages reduce the cluster performance obviously?

If I don't delete the index at once, but do it later. is it better? For example, if the system is busy, only update all key-values to empty value { } . When the cluster is idle, delete all related index in a bulk message.

Thanks

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [February 1, 2016, 6:34am UTC](https://discuss.elastic.co/t/delete-or-update-empty-value-which-is-more-efficient-in-es/40595/2 "2016-02-01T06:34:39Z")

</div>

Update operations are equivalent to deleting the old document and adding the updated document as a new document. Hence, update + delete is more expensive than just a delete.

---

<div class="post-metadata">

### Author: ![Gary\_Wu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gary_wu/32/4834_2.png) [@Gary\_Wu](https://discuss.elastic.co/u/Gary_Wu)
#### Post date: [February 1, 2016, 6:54am UTC](https://discuss.elastic.co/t/delete-or-update-empty-value-which-is-more-efficient-in-es/40595/3 "2016-02-01T06:54:08Z")

</div>

Hi @Magnus,  
Thank you for your reply. I still have a confusion. If I update only one key-value in the index, does the whole document be updated ?  
If the answer is no, I have another thought. I can add a new key-value flag (default "1" ) in every index, if the index is deleted, I just update the key-value flag to "0" because the system is busy. When the cluster is idle, I could delete all unused index which the flag is "0" in batch. Is it a reasonable idea?

Thanks

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [February 1, 2016, 7:12am UTC](https://discuss.elastic.co/t/delete-or-update-empty-value-which-is-more-efficient-in-es/40595/4 "2016-02-01T07:12:18Z")

</div>

> Thank you for your reply. I still have a confusion. If I update only one key-value in the index, does the whole document be updated ?

Yes.

> **[Updating Documents | Elasticsearch Guide \[2.1\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/2.1/_updating_documents.html)**

> If the answer is no, I have another thought. I can add a new key-value flag (default "1" ) in every index, if the index is deleted, I just update the key-value flag to "0" because the system is busy. When the cluster is idle, I could delete all unused index which the flag is "0" in batch. Is it a reasonable idea?

You mean you'd add a separate document that indicates whether the index is going to be deleted? How are you going to use that in your queries? Anyway, deleting the whole index is a cheap operation.

---

<div class="post-metadata">

### Author: ![Gary\_Wu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gary_wu/32/4834_2.png) [@Gary\_Wu](https://discuss.elastic.co/u/Gary_Wu)
#### Post date: [February 1, 2016, 8:22am UTC](https://discuss.elastic.co/t/delete-or-update-empty-value-which-is-more-efficient-in-es/40595/5 "2016-02-01T08:22:39Z")

</div>

Thanks a lot. From reference, I see every update will cause a old document is deleted(not at once, but do it later) and a new document is created. And the index is pointed to the new document.

There is a mistake in my last answer. I means that there is an additional field in every document. for example;

PUT /website/blog/123  
{

```
   "title": "My first blog entry",
   "text": "I am starting to get the hang of this...",
    "date": "2014/01/02"，
    "deleted_flag" : true

```

}  
After delete the document, the "deleted\_flag" will be updated to false.  
when query data every times, a extra condition should be added as below.  
GET /website/blog/123  
{

* * *

```
"query": {
       "filter":{
              "query" : {"match": xxxx } //some queries conditions
              "filter": { "term": { "deleted_flag": false}}, //extra judgement condition
       }
  }

```

}

I want to use esRdd of spark to do some operation in ES, but it seems that esRdd doesn't support delete operation. I am trying to find other optional plan for the same result in ES.

---

<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, 11:19pm UTC](https://discuss.elastic.co/t/delete-or-update-empty-value-which-is-more-efficient-in-es/40595/6 "2017-07-05T23:19:59Z")

</div>


