# Update document to remove a field / overwrite

**URL:** <https://discuss.elastic.co/t/update-document-to-remove-a-field-overwrite/200755>\
**Category:** Elasticsearch\
**Created:** [September 23, 2019, 8:39pm UTC](https://discuss.elastic.co/t/update-document-to-remove-a-field-overwrite/200755 "2019-09-23T20:39:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlaprade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dlaprade/32/47576_2.png) [@dlaprade](https://discuss.elastic.co/u/dlaprade)\
**Post date:** [September 23, 2019, 8:39pm UTC](https://discuss.elastic.co/t/update-document-to-remove-a-field-overwrite/200755/1 "2019-09-23T20:39:13Z")

</div>

ES: 6.8

I have a document like:

```
{ 
    "title": "mytitle",
    "description": "my description",
   "randomfield" : "random value"
}    

```

My index fields is title.

I would like to be able to update this document to remove a field like "randomfield" and add new fields. But playing around I noticed that I can set it to null but not remove it. Is there a way to have it override the current document with the new data being sent?

I am using the update API to save my changes: /my\_index/\_doc/my\_id/\_update

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![dlaprade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dlaprade/32/47576_2.png) [@dlaprade](https://discuss.elastic.co/u/dlaprade)\
**Post date:** [September 23, 2019, 10:05pm UTC](https://discuss.elastic.co/t/update-document-to-remove-a-field-overwrite/200755/2 "2019-09-23T22:05:39Z")

</div>

Is the only option to delete by ID, then re-create?

---

<div class="post-metadata">

**Author:** ![dlaprade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dlaprade/32/47576_2.png) [@dlaprade](https://discuss.elastic.co/u/dlaprade)\
**Post date:** [September 23, 2019, 11:02pm UTC](https://discuss.elastic.co/t/update-document-to-remove-a-field-overwrite/200755/3 "2019-09-23T23:02:35Z")

</div>

Could another option be to do a bulk call which includes first the delete of the record then a create of the record?

If i choose the bulk, I can add `_bulk?refresh=wait_for` which would limit visibility to search until all have completed.

Thoughts?

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [September 24, 2019, 1:49am UTC](https://discuss.elastic.co/t/update-document-to-remove-a-field-overwrite/200755/4 "2019-09-24T01:49:06Z")

</div>

Hi @dlaprade,

If you run an update it will be enough.

if you insert a document this way with 123 as id or you can keep it empty and elastic will set an id for you.

```auto
POST my_index/_doc/123
{ 
    "title": "mytitle",
    "description": "my description",
   "randomfield" : "random value"
}  

```

if you run again you'll save the new document without the "randomfiled"

```auto
POST my_index/_doc/123
{ 
    "title": "mytitle",
    "description": "my description",
}  

```

You don't need to run a bulk to delete and create.

If you make a GET on your 123 doc you'll get the last version without the "randomfield".

---

<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:** [October 22, 2019, 1:49am UTC](https://discuss.elastic.co/t/update-document-to-remove-a-field-overwrite/200755/5 "2019-10-22T01:49:12Z")

</div>

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