elasticsearch - Delete all documents from index/type without deleting type

ID : 20386

viewed : 32

Tags :

Top 5 Answer for elasticsearch - Delete all documents from index/type without deleting type

vote vote

96

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 

Note: XDELETE is deprecated for later versions of ElasticSearch

vote vote

88

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' -H 'Content-Type: application/json' -d' {     "query": {         "match_all": {}     } }' 
vote vote

75

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

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

{     "query": {          "match_all": {}     } } 
vote vote

70

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

vote vote

51

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)

Top 3 video Explaining elasticsearch - Delete all documents from index/type without deleting type

Related QUESTION?