Delete Documents Flashcards
Delete a single document
DELETE /my_index/_doc/1
This deletes the document with the ID 1 from the my_index index.
Delete by Query
POST /my_index/_delete_by_query
{
“query”: {
“term”: {
“status”: “archived”
}
}
}
In this example, all documents in the my_index index where the status field is “archived” will be deleted.
Delete All Documents from an Index
POST /my_index/_delete_by_query
{
“query”: {
“match_all”: {}
}
}
Delete Documents from Multiple Indices
POST /index1,index2/_delete_by_query
{
“query”: {
“term”: {
“category”: “obsolete”
}
}
}
Query Params
POST /my_index/_delete_by_query?conflicts=proceed
POST /my_index/_delete_by_query?refresh=true
conflicts: Set to “proceed” to continue deleting even if there are version conflicts.
refresh: Set to true to force a refresh after the delete operation
batch_size parameter
POST /my_index/_delete_by_query
{
“query”: {
“term”: {
“status”: “archived”
}
},
“size”: 1000
}
Use the size parameter to control the batch size of each scroll request.