Bird
Raised Fist0
Elasticsearchquery~20 mins

Deleting documents in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Elasticsearch Delete Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this delete request?

Given this Elasticsearch delete request, what is the expected response status?

Elasticsearch
DELETE /library/_doc/123
A{"result":"deleted"}
B{"result":"not_found"}
C{"error":"index_not_found_exception"}
D{"result":"updated"}
Attempts:
2 left
💡 Hint

If the document exists, deleting it returns a deleted result.

❓ Predict Output
intermediate
2:00remaining
What happens if you delete a non-existing document?

What is the response when deleting a document that does not exist in the index?

Elasticsearch
DELETE /library/_doc/9999
A{"result":"deleted"}
B{"result":"created"}
C{"error":"document_missing_exception"}
D{"result":"not_found"}
Attempts:
2 left
💡 Hint

Deleting a non-existing document returns not_found in the result.

🔧 Debug
advanced
2:00remaining
Why does this delete request fail with an error?

Identify the error in this delete request and the cause of failure.

Elasticsearch
DELETE /library/_doc/
ASyntaxError: Missing document ID in the URL
BIndexNotFoundException: The index 'library' does not exist
CTypeError: Invalid HTTP method
DSuccess: Document deleted
Attempts:
2 left
💡 Hint

The delete API requires a document ID after the type.

🧠 Conceptual
advanced
2:00remaining
Which option correctly deletes documents matching a query?

Which Elasticsearch API call deletes all documents where status is obsolete?

APOST /library/_delete {"query": {"match_all": {}}}
BPOST /library/_delete_by_query {"query": {"term": {"status": "obsolete"}}}
CDELETE /library/_delete_by_query {"query": {"term": {"status": "obsolete"}}}
DDELETE /library/_doc/_query {"term": {"status": "obsolete"}}
Attempts:
2 left
💡 Hint

The _delete_by_query API deletes documents matching a query.

📝 Syntax
expert
2:00remaining
What error does this delete request produce?

What error results from this malformed delete request?

Elasticsearch
DELETE /library/_doc/123 {"query": {"match_all": {}}}
A500 Internal Server Error
B404 Not Found: Document does not exist
C400 Bad Request: Request body not allowed for DELETE on document API
D200 OK: Document deleted successfully
Attempts:
2 left
💡 Hint

The document delete API does not accept a request body.

Practice

(1/5)
1.

Which Elasticsearch API method is used to delete a single document by its ID?

easy
A. GET method with document ID
B. DELETE method with document ID
C. POST method with document ID
D. PUT method with document ID

Solution

  1. Step 1: Understand document deletion in Elasticsearch

    Deleting a single document requires specifying its ID and using the DELETE HTTP method.
  2. Step 2: Identify the correct API method

    The DELETE method with the document ID is the standard way to remove one document.
  3. Final Answer:

    DELETE method with document ID -> Option B
  4. Quick Check:

    Delete single document = DELETE with ID [OK]
Hint: Use DELETE with document ID to remove one document fast [OK]
Common Mistakes:
  • Using GET or POST instead of DELETE
  • Trying to delete without specifying document ID
  • Confusing _delete_by_query with single document deletion
2.

Which of the following is the correct syntax to delete a document with ID 123 from index products using Elasticsearch REST API?

?
easy
A. GET /products/_delete/123
B. POST /products/_doc/123/_delete
C. DELETE /products/_doc/123
D. PUT /products/_doc/123

Solution

  1. Step 1: Recall the REST API syntax for deleting a document

    The correct syntax uses DELETE method on the path /index/_doc/document_id.
  2. Step 2: Match the syntax with the options

    DELETE /products/_doc/123 matches DELETE /products/_doc/123 which is correct.
  3. Final Answer:

    DELETE /products/_doc/123 -> Option C
  4. Quick Check:

    Delete syntax = DELETE /index/_doc/id [OK]
Hint: DELETE + /index/_doc/document_id is the right syntax [OK]
Common Mistakes:
  • Using POST or GET instead of DELETE
  • Wrong URL path like _delete or missing _doc
  • Using PUT which is for creating/updating
3.

Given this Elasticsearch _delete_by_query request to delete documents where status is "inactive":

{
  "query": {
    "term": { "status": "inactive" }
  }
}

What will be the result if there are 3 documents matching this query?

medium
A. Deletes 3 documents and returns success count 3
B. Deletes 0 documents because term query is incorrect
C. Deletes all documents in the index
D. Returns an error due to missing document ID

Solution

  1. Step 1: Understand _delete_by_query behavior

    It deletes all documents matching the query, here documents with status "inactive".
  2. Step 2: Apply to given query and data

    Since 3 documents match, all 3 will be deleted and success count will be 3.
  3. Final Answer:

    Deletes 3 documents and returns success count 3 -> Option A
  4. Quick Check:

    _delete_by_query deletes matching docs = 3 [OK]
Hint: Delete by query removes all matching docs, not just one [OK]
Common Mistakes:
  • Thinking _delete_by_query needs document ID
  • Assuming it deletes all documents regardless of query
  • Confusing term query syntax
4.

What is wrong with this Elasticsearch delete request?

DELETE /users/_doc

It aims to delete a document but fails. Why?

medium
A. Missing document ID in the URL
B. Using DELETE instead of POST
C. Index name is incorrect
D. Missing request body with query

Solution

  1. Step 1: Check the delete request URL format

    Deleting a document requires the document ID after _doc in the URL.
  2. Step 2: Identify the missing part

    The request lacks the document ID, so Elasticsearch cannot identify which document to delete.
  3. Final Answer:

    Missing document ID in the URL -> Option A
  4. Quick Check:

    Delete URL needs document ID [OK]
Hint: Always include document ID after _doc in DELETE URL [OK]
Common Mistakes:
  • Omitting document ID in delete URL
  • Confusing DELETE with POST for deletion
  • Thinking request body is needed for single delete
5.

You want to delete all documents from the orders index where the amount field is less than 100. Which Elasticsearch request correctly achieves this?

hard
A. DELETE /orders/_delete_by_query { "query": { "term": { "amount": 100 } } }
B. DELETE /orders/_doc { "query": { "range": { "amount": { "lt": 100 } } } }
C. POST /orders/_doc/amount_lt_100/_delete
D. POST /orders/_delete_by_query { "query": { "range": { "amount": { "lt": 100 } } } }

Solution

  1. Step 1: Identify the correct API for deleting multiple documents by condition

    _delete_by_query is used with POST to delete documents matching a query.
  2. Step 2: Check the query for amount less than 100

    The range query with "lt": 100 correctly matches documents with amount less than 100.
  3. Step 3: Verify the request method and path

    POST /orders/_delete_by_query with the correct JSON body is the proper syntax.
  4. Final Answer:

    POST /orders/_delete_by_query { "query": { "range": { "amount": { "lt": 100 } } } } -> Option D
  5. Quick Check:

    Delete by query with range and POST = correct [OK]
Hint: Use POST _delete_by_query with range query for conditional deletes [OK]
Common Mistakes:
  • Using DELETE method with request body (not supported)
  • Using _doc endpoint instead of _delete_by_query
  • Using term query instead of range for less than condition
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard