Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a field from a Elasticsearch document

I need to remove a field in all the documents indexed to Elasticsearch. How can I do it?

like image 956
Jalal Avatar asked Mar 12 '15 05:03

Jalal


People also ask

How do I remove a mapping field in Elasticsearch?

You cannot delete the status field from this mapping. If you really need to get rid of this field, you'll have to create another mapping without status field and reindex your data.

How do I delete a field in Kibana?

You have to delete and re-index the indices still containing the field with the updated mapping. Then you can go to the index pattern management page in Kibana and refresh the index pattern there using the reload button in the top right. This should remove the fields from the index pattern as well.

How do I delete a specific index in Elasticsearch?

To delete the index, you must roll over the data stream so a new write index is created. You can then use the delete index API to delete the previous write index.


1 Answers

What @backtrack told is true , but then there is a very convenient way of doing this in Elasticsearch. Elasticsearch will abstract out the internal complexity of the deletion. You need to use update API to achieve this -

curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{     "script" : "ctx._source.remove(\"name_of_field\")" }' 

You can find more documentation here.

Note: As of Elastic Search 6 you are required to include a content-type header:

-H 'Content-Type: application/json' 
like image 84
Vineeth Mohan Avatar answered Sep 19 '22 23:09

Vineeth Mohan