You can delete one or more indices, which really deletes their files from disk. For example:
curl -XDELETE localhost:9200/$INDEXNAME
Where $INDEXNAME
can be an index name (e.g. users_v2
), N indices separated by comma (e.g. users_v2,users_v3
). An index pattern (e.g. users_*
) or _all
, also works, unless it's blocked in the config via action.destructive_requires_name: true
.
Deleting individual documents is possible, but this won't immediately purge them. A delete is only a soft delete, and documents are really removed during segment merges. You'll find lots of details about segments and merges in this presentation. It's about Solr, but merges are from Lucene, so you have the same options in Elasticsearch.
Back to the API, you can either delete individual documents by ID (provide a routing value if you index with routing):
curl -XDELETE localhost:9200/users_v2/_doc/user1
Or by query:
curl -XPOST -H 'Content-Type: application/json' localhost:9200/users_v2/_delete_by_query -d '{
"query": {
"match": {
"description_field": "bad user"
}
}
}'