Reputation: 288
Is it possible to delete all the documents of a particular type in the elasticsearch index ? - Does it affect the type mapping too ? - I want to retain the mapping for that type.
Using elasticsearch 2.2
Upvotes: 0
Views: 43
Reputation: 2255
Found an answer related to this here. Following content is directly from that answer.
You can use the delete-by-query plugin43 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.
P.S: This plugin is there in 2.x version and not there in 5.x. So in 5.x there can be other ways to do this. I believe that this deletion does not affect the mapping because this just deletes individual documents.
Upvotes: 1