Update document to remove a field / overwrite

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.

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

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?

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.

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"

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".

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