Delete all documents from index/type without deleting type

后端 未结 15 453
耶瑟儿~
耶瑟儿~ 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:17

    I believe if you combine the delete by query with a match all it should do what you are looking for, something like this (using your example):

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

    Or you could just delete the type:

    curl -XDELETE http://localhost:9200/twitter/tweet
    
    0 讨论(0)
  • 2020-12-04 10:17

    If you want to delete document according to a date. You can use kibana console (v.6.1.2)

    POST index_name/_delete_by_query
    {
          "query" : {
                  "range" : {
                     "sendDate" : {
                         "lte" : "2018-03-06"
                                  }
                            }
                      }
    }
    
    0 讨论(0)
  • 2020-12-04 10:19

    You can delete documents from type with following query:

    POST /index/type/_delete_by_query
    {
        "query" : { 
            "match_all" : {}
        }
    }
    

    I tested this query in Kibana and Elastic 5.5.2

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

    You have these alternatives:

    1) Delete a whole index:

    curl -XDELETE 'http://localhost:9200/indexName'             
    

    example:

    curl -XDELETE 'http://localhost:9200/mentorz'
    

    For more details you can find here -https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html

    2) Delete by Query to those that match:

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

    *Here mentorz is an index name and users is a type

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

    The above answers no longer work with ES 6.2.2 because of Strict Content-Type Checking for Elasticsearch REST Requests. The curl command which I ended up using is this:

    curl -H'Content-Type: application/json' -XPOST 'localhost:9200/yourindex/_doc/_delete_by_query?conflicts=proceed' -d' { "query": { "match_all": {} }}'
    
    0 讨论(0)
  • 2020-12-04 10:21

    The Delete-By-Query plugin has been removed in favor of a new Delete By Query API implementation in core. Read here

    curl -XPOST 'localhost:9200/twitter/tweet/_delete_by_query?conflicts=proceed&pretty' -d'
    {
        "query": {
            "match_all": {}
        }
    }'
    
    0 讨论(0)
提交回复
热议问题