0

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

1

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Rajind! So, there is no way I can delete all the documents of a particular type without installing the delete-by-query plugin in elasticsearch-2.2 ?
@shan As far as I know, there is no other way.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.