Delete documents of type in Elasticsearch

前端 未结 7 1457
南旧
南旧 2021-02-18 16:50

I want to delete all the documents indexed within a type in Elasticsearch, using the HTTP/REST api, but I don\'t want to delete the mapping for this type

How can I build

7条回答
  •  面向向阳花
    2021-02-18 17:23

    Previous answers will not work with the most recent version of Elasticsearch. "Delete by query" was deprecated from Elasticsearch 2.0. Elasticsearch documentation says that it can cause an OutOfMemoryError during concurrent indexing and can cause primary and replica to become inconsistent. If you want follow the history of the issue in Github.

    It now takes multiple steps in order to delete all documents from a type.

    1. Find all the ids of the document that you need to delete. The most efficient way to perform this operation is to use the scroll/scan API to find all the matching ids for a given type.

    2. Issue a bulk request to delete the documents by ids. An example provided below.

      curl -XPOST 'http://localhost:9200/_bulk' -d '
          { "delete": { "_index": "index", "_type": "type", "_id": "1"}
          { "delete": { "_index": "index", "_type": "type", "_id": "2"}'
      

    Note that if you are providing a text file input to curl, you must use the --data-binary flag instead of plain -d.

提交回复
热议问题