Challenge - 5 Problems
Elasticsearch Update Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Elasticsearch update script?
Given the following update request, what will be the value of the field
counter after the update?Elasticsearch
{
"script" : {
"source" : "ctx._source.counter += params.count",
"params" : {
"count" : 4
}
}
}Attempts:
2 left
💡 Hint
Look at the script source and the operation it performs on
ctx._source.counter.✗ Incorrect
The script uses
ctx._source.counter += params.count which means it adds the value of params.count (4) to the existing counter field. So the field increases by 4.❓ Predict Output
intermediate2:00remaining
What happens if you try to update a non-existent document?
Consider this update request targeting a document ID that does not exist. What is the expected result?
Elasticsearch
{
"doc" : {
"status" : "active"
}
}Attempts:
2 left
💡 Hint
Think about the default behavior of update requests on missing documents.
✗ Incorrect
By default, an update request on a non-existent document returns a 404 error. It does not create a new document unless
doc_as_upsert is set to true.🔧 Debug
advanced3:00remaining
Why does this update script fail with a runtime error?
This update script is intended to append a new tag to the
tags array. Why does it fail?Elasticsearch
{
"script": {
"source": "ctx._source.tags.add(params.new_tag)",
"params": {
"new_tag": "urgent"
}
}
}Attempts:
2 left
💡 Hint
Check if the
tags field exists and is an array before calling add.✗ Incorrect
If
tags is missing or null, calling add on it causes a runtime error because you cannot call methods on null.📝 Syntax
advanced3:00remaining
Which update script syntax is correct to conditionally update a field?
You want to update the
status field to "closed" only if its current value is "open". Which script is correct?Attempts:
2 left
💡 Hint
Check the syntax for if statements and equality operators in painless scripts.
✗ Incorrect
Option C uses correct painless script syntax: parentheses around condition, double equals for comparison, and braces for the block.
🚀 Application
expert4:00remaining
How to atomically increment a nested field in an update request?
You have a document with a nested field
metrics.views. Which update request correctly increments views by 1 atomically?Attempts:
2 left
💡 Hint
Think about how to access nested fields in painless scripts and how to increment them.
✗ Incorrect
Option A correctly uses painless script syntax to increment the nested field
metrics.views. Options B and D try to update with strings, which is invalid. Option A uses incorrect syntax for nested field access.