Bird
0
0

You want to retrieve a document by ID but also handle the case when the document is missing without causing an error. Which approach is best?

hard🚀 Application Q15 of 15
Elasticsearch - Document Operations
You want to retrieve a document by ID but also handle the case when the document is missing without causing an error. Which approach is best?
AUse a search query with term _id and expect zero hits if missing
BUse GET /index/_doc/id and check if 'found' is true in the response
CUse GET /index/_doc/id and catch HTTP 404 error to handle missing
DUse scroll API to find the document and handle empty results
Step-by-Step Solution
Solution:
  1. Step 1: Understand GET by ID response behavior

    GET by ID returns a JSON with 'found': false if the document is missing, no error thrown.
  2. Step 2: Compare with other methods

    Search queries return hits but are slower; catching HTTP 404 is unnecessary; scroll API is for multiple docs.
  3. Final Answer:

    Use GET /index/_doc/id and check if 'found' is true in the response -> Option B
  4. Quick Check:

    Check 'found' field to detect missing document [OK]
Quick Trick: Check 'found' in GET response to detect missing docs safely [OK]
Common Mistakes:
MISTAKES
  • Expecting HTTP 404 error for missing documents
  • Using search queries instead of GET by ID
  • Using scroll API for single document retrieval

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes