Delete documents of type in Elasticsearch

user2816801 picture user2816801 · Sep 25, 2013 · Viewed 27.8k times · Source

I want to delete all the documents indexed within a type in Elasticsearch, using the HTTP/REST api, but I don't want to delete the mapping for this type

How can I build the query in the URL to do this?

Answer

csonuryilmaz picture csonuryilmaz · May 15, 2014

Before executing command, index/mapping state; (screenshots taken from elasticsearch head plugin web interface)

enter image description here

enter image description here

enter image description here

Command;

curl -XDELETE 'http://localhost:9200/publishercategoryeu/autocomplete/_query' -d '
{
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        }
      ]
    }
  }
}
'

Result;

enter image description here

After executing command, index/mapping state;

enter image description here

enter image description here

enter image description here

As we can see we deleted all the documents indexed within a type(mapping) without delete index or type(mapping).