Remove a field from a Elasticsearch document

后端 未结 5 1096
长情又很酷
长情又很酷 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:20

    You can use _update_by_query

    Example 1

    index: my_index

    field: user.email

    POST my_index/_update_by_query?conflicts=proceed
    {
        "script" : "ctx._source.user.remove('email')",
        "query" : {
            "exists": { "field": "user.email" }
        }
    }
    

    Example 2

    index: my_index

    field: total_items

    POST my_index/_update_by_query?conflicts=proceed
    {
        "script" : "ctx._source.remove('total_items')",
        "query" : {
            "exists": { "field": "total_items" }
        }
    }
    

提交回复
热议问题