Deleting all document from an index type

How to delete all documents from an indextype, i have tried multiple options of DELETE using sense tool.

I can delete record by record specifying id, but not all, can anyone tell me is this requires any plugin for ES 2.1.0.

Thanks,
Chala

Hi,

you can use the delete-by-query plugin for that. Here's an example:

We create an index with two types and add some documents:

POST /_bulk
{"index":{"_index":"mammals","_type":"people"}}
{"tag_line":"I am Mike"}
{"index":{"_index":"mammals","_type":"people"}}
{"tag_line":"I am Hanna"}
{"index":{"_index":"mammals","_type":"people"}}
{"tag_line":"I am Bert"}
{"index":{"_index":"mammals","_type":"animals"}}
{"tag_line":"I am a dog"}
{"index":{"_index":"mammals","_type":"animals"}}
{"tag_line":"I am a cat"}

When we query for all documents, we get 5 results:

GET /mammals/_search?size=0
{
    "query": {
        "match_all": {}
    }
}

Now we can delete all documents of the type "animals":

DELETE /mammals/animals/_query
{
    "query": {
        "match_all": {}
    }
}

This will only work when the delete-by-query plugin is installed.

When we search once again for all documents, we only get 3 results as the animals are gone.

Daniel

Thanks Daniel, after installing delete-by-query plugin its working.