Remove a field from a Elasticsearch document

后端 未结 5 1092
长情又很酷
长情又很酷 2020-12-02 13:00

I need to remove a field in all the documents indexed to Elasticsearch . How can i do it. Will any of the delete queries help me achieve this.

5条回答
  •  北海茫月
    2020-12-02 13:41

    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'
    

提交回复
热议问题