Delete all documents from index/type without deleting type

后端 未结 15 454
耶瑟儿~
耶瑟儿~ 2020-12-04 09:45

I know one can delete all documents from a certain type via deleteByQuery.

Example:

curl -XDELETE \'http://localhost:9200/twitter/tweet/_query\' -d \         


        
相关标签:
15条回答
  • 2020-12-04 10:21

    From ElasticSearch 5.x, delete_by_query API is there by default

    POST: http://localhost:9200/index/type/_delete_by_query

    {
        "query": { 
            "match_all": {}
        }
    }
    
    0 讨论(0)
  • 2020-12-04 10:24

    (Reputation not high enough to comment) The second part of John Petrone's answer works - no query needed. It will delete the type and all documents contained in that type, but that can just be re-created whenever you index a new document to that type.

    Just to clarify: $ curl -XDELETE 'http://localhost:9200/twitter/tweet'

    Note: this does delete the mapping! But as mentioned before, it can be easily re-mapped by creating a new document.

    0 讨论(0)
  • 2020-12-04 10:27

    In Kibana Console:

    POST calls-xin-test-2/_delete_by_query
    {
      "query": { 
        "match_all": {}
      }
    }
    
    0 讨论(0)
  • 2020-12-04 10:27

    Note for ES2+

    Starting with ES 1.5.3 the delete-by-query API is deprecated, and is completely removed since ES 2.0

    Instead of the API, the Delete By Query is now a plugin.

    In order to use the Delete By Query plugin you must install the plugin on all nodes of the cluster:

    sudo bin/plugin install delete-by-query
    

    All of the nodes must be restarted after the installation.


    The usage of the plugin is the same as the old API. You don't need to change anything in your queries - this plugin will just make them work.


    *For complete information regarding WHY the API was removed you can read more here.

    0 讨论(0)
  • 2020-12-04 10:30

    Just to add couple cents to this.

    The "delete_by_query" mentioned at the top is still available as a plugin in elasticsearch 2.x.

    Although in the latest upcoming version 5.x it will be replaced by "delete by query api"

    0 讨论(0)
  • 2020-12-04 10:31

    Torsten Engelbrecht's comment in John Petrones answer expanded:

    curl -XDELETE 'http://localhost:9200/twitter/tweet/_query' -d 
      '{
          "query": 
          {
              "match_all": {}
          }
       }'
    

    (I did not want to edit John's reply, since it got upvotes and is set as answer, and I might have introduced an error)

    0 讨论(0)
提交回复
热议问题