0
0
Elasticsearchquery~20 mins

Indexing a document (POST/PUT) in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Elasticsearch Indexing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the result of this indexing request?
Given the following Elasticsearch indexing request, what will be the status in the response if the document is successfully indexed?
Elasticsearch
POST /library/_doc/1
{
  "title": "Learn Elasticsearch",
  "author": "Jane Doe",
  "year": 2023
}
A{"_index":"library","_id":"1","result":"deleted"}
B{"_index":"library","_id":"1","result":"updated"}
C{"_index":"library","_id":"1","result":"created"}
D{"_index":"library","_id":"1","result":"error"}
Attempts:
2 left
💡 Hint
When you use POST with a new document ID, Elasticsearch creates the document.
Predict Output
intermediate
2:00remaining
What happens when you PUT a document with an existing ID?
Consider this request to update a document by ID using PUT. What will the 'result' field show if the document already exists?
Elasticsearch
PUT /library/_doc/1
{
  "title": "Mastering Elasticsearch",
  "author": "Jane Doe",
  "year": 2024
}
A{"_index":"library","_id":"1","result":"updated"}
B{"_index":"library","_id":"1","result":"created"}
C{"_index":"library","_id":"1","result":"noop"}
D{"_index":"library","_id":"1","result":"deleted"}
Attempts:
2 left
💡 Hint
PUT with an existing ID replaces the document, so it updates.
🧠 Conceptual
advanced
1:30remaining
Which HTTP method is idempotent for indexing documents?
In Elasticsearch, which HTTP method ensures that multiple identical requests have the same effect on the document store?
APUT
BGET
CPOST
DDELETE
Attempts:
2 left
💡 Hint
Idempotent means the same request repeated does not change the result after the first time.
Predict Output
advanced
2:00remaining
What error occurs if you try to index a document with invalid JSON?
What error will Elasticsearch return if you send this indexing request with malformed JSON?
Elasticsearch
POST /library/_doc
{
  "title": "Invalid JSON",
  "author": "John Doe",
  "year": 2023
}
A{"error":{"type":"version_conflict_engine_exception","reason":"version conflict"}}
B{"error":{"type":"json_parse_exception","reason":"Unexpected character ('}' at position...)"}}
C{"error":{"type":"index_not_found_exception","reason":"no such index"}}
D{"result":"created"}
Attempts:
2 left
💡 Hint
Malformed JSON causes a parsing error before indexing.
🧠 Conceptual
expert
2:30remaining
What is the difference in behavior between POST and PUT when indexing documents without specifying an ID?
In Elasticsearch, when you index a document without specifying an ID, what is the difference in behavior between using POST and PUT methods?
ABoth POST and PUT require an ID and will fail if none is specified.
BPUT auto-generates an ID; POST requires an ID and will fail without it.
CBoth POST and PUT auto-generate IDs if none are specified.
DPOST auto-generates an ID; PUT requires an ID and will fail without it.
Attempts:
2 left
💡 Hint
Think about which method allows auto ID generation.