0
0
Elasticsearchquery~10 mins

Deleting documents in Elasticsearch - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Deleting documents
Start
Send Delete Request
Check Document Exists?
NoReturn Not Found
Yes
Delete Document
Return Success Response
End
The flow shows sending a delete request, checking if the document exists, deleting it if found, and returning the result.
Execution Sample
Elasticsearch
DELETE /my_index/_doc/1

# Deletes document with ID 1 from 'my_index'
This command deletes the document with ID 1 from the index named 'my_index'.
Execution Table
StepActionRequest SentDocument Exists?ResultResponse
1Send DELETE request to /my_index/_doc/1DELETE /my_index/_doc/1Check if document with ID 1 existsYesProceed to delete
2Delete document with ID 1N/AN/ADeleted200 OK with result 'deleted'
3Return responseN/AN/ASuccess{"result":"deleted"}
4EndN/AN/AN/AN/A
💡 Document with ID 1 deleted successfully, operation ends.
Variable Tracker
VariableStartAfter Step 1After Step 2Final
document_existsunknowntruedeleteddeleted
responsenonepending{"result":"deleted"}{"result":"deleted"}
Key Moments - 2 Insights
What happens if the document does not exist when the delete request is sent?
If the document does not exist, the response will indicate 'not_found' instead of 'deleted'. This is shown in the execution_table step 1 where document existence is checked.
Does the delete request remove the entire index?
No, the delete request targets a single document by its ID. The index remains intact. This is clear from the request path /my_index/_doc/1 which specifies one document.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the response after the document is deleted?
A{"result":"deleted"}
B{"result":"not_found"}
C404 Not Found
D500 Internal Server Error
💡 Hint
Check the Response column at Step 3 in the execution_table.
At which step does the system confirm the document exists before deleting?
AStep 3
BStep 1
CStep 2
DStep 4
💡 Hint
Look at the Document Exists? column in the execution_table.
If the document did not exist, how would the response change?
AResponse would be 200 OK with no body
BResponse would be {"result":"deleted"}
CResponse would be {"result":"not_found"}
DResponse would be 500 Internal Server Error
💡 Hint
Refer to key_moments about document existence and response.
Concept Snapshot
Deleting documents in Elasticsearch:
- Use DELETE /index/_doc/document_id
- Checks if document exists
- If yes, deletes and returns {"result":"deleted"}
- If no, returns {"result":"not_found"}
- Does not delete the whole index
Full Transcript
This visual execution shows how deleting a document in Elasticsearch works step-by-step. First, a DELETE request is sent to the document's URL. The system checks if the document exists. If it does, the document is deleted and a success response with {"result":"deleted"} is returned. If the document does not exist, the response indicates {"result":"not_found"}. The index itself remains unchanged. Variables like document_exists and response update as the process runs. This helps beginners see exactly what happens behind the scenes when deleting documents.