0
0
Elasticsearchquery~20 mins

Bulk API for batch operations in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Bulk API 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 Bulk API request?

Consider the following Bulk API request sent to Elasticsearch. What will be the result in the response for the items array?

Elasticsearch
{ "index": { "_index": "products", "_id": "1" } }
{ "name": "Laptop", "price": 1200 }
{ "delete": { "_index": "products", "_id": "2" } }
{ "update": { "_index": "products", "_id": "3" } }
{ "doc": { "price": 900 } }
AThe response will contain 4 items: one index success, one delete success, one update success, and one error because the update body is missing the 'doc' key.
BThe response will contain 3 items: index success, delete success, and an error for the update because the update body is malformed.
CThe response will contain 4 items: index success, delete success, update success, and an error because the delete operation is missing a body.
DThe response will contain 3 items: index success, delete success, and update success with the price updated to 900.
Attempts:
2 left
💡 Hint

Remember that each action line must be followed by its data line except for delete operations which do not require a data line.

🧠 Conceptual
intermediate
1:30remaining
How does the Bulk API handle partial failures?

When sending a Bulk API request with multiple operations, how does Elasticsearch handle partial failures?

AElasticsearch processes all operations and returns individual success or failure status for each operation in the response.
BElasticsearch ignores failures and returns success for all operations regardless of errors.
CElasticsearch retries failed operations automatically until they succeed or a timeout occurs.
DElasticsearch stops processing at the first failure and returns an error for the entire bulk request.
Attempts:
2 left
💡 Hint

Think about how batch processing usually reports results.

🔧 Debug
advanced
2:30remaining
Identify the error in this Bulk API request

Review the following Bulk API request. What error will Elasticsearch return?

Elasticsearch
{ "index": { "_index": "users", "_id": "10" } }
{ "name": "Alice" }
{ "update": { "_index": "users", "_id": "11" } }
{ "price": 100 }
{ "delete": { "_index": "users", "_id": "12" } }
{ "index": { "_index": "users", "_id": "13" } }
AA syntax error because the last index operation is missing its data line.
BAn error because the update operation's data line is missing the 'doc' key.
CAn error because the delete operation has an unexpected data line following it.
DNo error; all operations are valid and will succeed.
Attempts:
2 left
💡 Hint

Check if every action line that requires a data line has one.

📝 Syntax
advanced
1:30remaining
Which Bulk API request syntax is correct?

Choose the correct Bulk API request syntax to update a document with ID '5' in index 'orders' to set the field 'status' to 'shipped'.

A
{ "doc": { "status": "shipped" } }
{ "update": { "_index": "orders", "_id": "5" } }
B
{ "update": { "_index": "orders", "_id": "5" } }
{ "doc": { "status": "shipped" } }
C
{ "update": { "_index": "orders", "_id": "5" } }
{ "status": "shipped" }
D{ "update": { "_index": "orders", "_id": "5", "doc": { "status": "shipped" } } }
Attempts:
2 left
💡 Hint

Remember the Bulk API requires an action line followed by a data line for update operations.

🚀 Application
expert
2:30remaining
How many items will be in the response for this Bulk API request?

Given the following Bulk API request with 4 action lines, how many items will the response contain?

Elasticsearch
{ "index": { "_index": "logs", "_id": "100" } }
{ "message": "start" }
{ "delete": { "_index": "logs", "_id": "101" } }
{ "update": { "_index": "logs", "_id": "102" } }
{ "doc": { "status": "done" } }
{ "index": { "_index": "logs", "_id": "103" } }
{ "message": "end" }
A3 items, because the last index operation is missing a data line and will cause an error.
B5 items, one for each action line.
C4 items, because delete operations do not have a data line and are counted as one item.
D6 items, counting both action and data lines separately.
Attempts:
2 left
💡 Hint

Count the number of operations, not lines, and remember delete operations do not have data lines.