Delete all documents from index/type without deleting type

Michael Leiss picture Michael Leiss · May 28, 2014 · Viewed 192.9k times · Source

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

Example:

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

But i have NO term and simply want to delete all documents from that type, no matter what term. What is best practice to achieve this? Empty term does not work.

Link to deleteByQuery

Answer

John Petrone picture John Petrone · May 28, 2014

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