Challenge - 5 Problems
Elasticsearch Partial 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 partial update script?
Given the following Elasticsearch update request, what will be the value of the
counter field after the update?Elasticsearch
{
"script": {
"source": "ctx._source.counter += params.increment",
"params": {"increment": 3}
}
}Attempts:
2 left
💡 Hint
Think about how the script modifies the existing field value.
✗ Incorrect
The script uses
ctx._source.counter += params.increment which adds 3 to the existing counter value. It does not overwrite or remove it.❓ Predict Output
intermediate2:00remaining
What happens if you use a partial update with a nested field?
Consider this partial update request to change a nested field
address.city. What will be the result?Elasticsearch
{
"doc": {
"address": {
"city": "Newville"
}
}
}Attempts:
2 left
💡 Hint
Partial updates merge the provided fields into the existing document.
✗ Incorrect
Partial updates merge the provided nested fields into the existing object, so only
city changes while other address fields stay the same.🔧 Debug
advanced2:00remaining
Why does this partial update script cause an error?
This update script is intended to add a tag to a list field
tags. 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 initialized as a list.✗ Incorrect
If
tags is missing or null, calling add on it causes an error. You must ensure tags is a list before adding.🧠 Conceptual
advanced2:00remaining
What is the effect of using
doc_as_upsert in a partial update?When you set
doc_as_upsert to true in an update request, what happens if the document does not exist?Attempts:
2 left
💡 Hint
Think about how upsert works in Elasticsearch.
✗ Incorrect
Setting
doc_as_upsert to true means if the document does not exist, Elasticsearch inserts the partial document as a new one.❓ Predict Output
expert3:00remaining
What is the final document after this partial update with a script?
Given the document
{"count": 5, "tags": ["old"]} and this update request, what is the final document?Elasticsearch
{
"script": {
"source": "ctx._source.count = params.count; ctx._source.tags.add(params.tag)",
"params": {"count": 10, "tag": "new"}
}
}Attempts:
2 left
💡 Hint
The script sets count and adds a tag to the existing list.
✗ Incorrect
The script sets
count to 10 and adds "new" to the existing tags list, resulting in {"count": 10, "tags": ["old", "new"]}.