Problem:
Need to delete indices and documents created in previous steps. Need to selectively delete documents.
Solution Summary:
We can send a DELETE http request to delete indices or documents. We can use the delete_by_query API to delete selectively.
Prerequisites:
Solution Steps:
Delete Document
DELETE /employee/_doc/1/
Resonse:
{
"_index": "employee",
"_type": "_doc",
"_id": "1",
"_version": 3,
"result": "deleted",
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 16,
"_primary_term": 1
}
Delete By Query
POST /employee/_delete_by_query
{
"query": {
"match": {
"_id":2
}
}
}
Note: You can match against any field. _id is one of the metadata fields. Match queries will be discussed in detail later.
Additional Notes:
-
Every time a batch of documents is found when using _delete_by_query, a corresponding bulk request is executed to delete all these documents.
-
It is much more efficient to delete a whole index instead of deleting all documents with the Delete By Query API.
Delete Index
DELETE /employee
Recent comments