0
0
Elasticsearchquery~20 mins

Partial updates in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Elasticsearch Partial Update 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 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}
  }
}
AThe <code>counter</code> field will be set to 3 regardless of its previous value.
BThe <code>counter</code> field will increase by 3 from its current value.
CThe update will fail because <code>ctx._source.counter</code> is not defined.
DThe <code>counter</code> field will be removed from the document.
Attempts:
2 left
💡 Hint
Think about how the script modifies the existing field value.
Predict Output
intermediate
2: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"
    }
  }
}
AOnly the <code>city</code> inside <code>address</code> is updated; other <code>address</code> fields remain unchanged.
BThe entire <code>address</code> object is replaced with {"city": "Newville"}.
CThe update will fail because nested fields cannot be updated partially.
DThe <code>city</code> field is added at the root level, not inside <code>address</code>.
Attempts:
2 left
💡 Hint
Partial updates merge the provided fields into the existing document.
🔧 Debug
advanced
2: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"}
  }
}
AThe <code>add</code> method is not supported in Elasticsearch scripts.
BThe script syntax is invalid because it lacks a return statement.
CThe parameter <code>new_tag</code> is not passed correctly.
DThe <code>tags</code> field is null or missing, so calling <code>add</code> causes a NullPointerException.
Attempts:
2 left
💡 Hint
Check if the tags field exists and is initialized as a list.
🧠 Conceptual
advanced
2: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?
AThe partial document is inserted as a new document.
BThe update fails with a document not found error.
CThe update request is ignored silently.
DA new empty document is created without the partial fields.
Attempts:
2 left
💡 Hint
Think about how upsert works in Elasticsearch.
Predict Output
expert
3: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"}
  }
}
A{"count": 5, "tags": ["old", "new"]}
B{"count": 10, "tags": ["new"]}
C{"count": 10, "tags": ["old", "new"]}
DThe update fails with a NullPointerException.
Attempts:
2 left
💡 Hint
The script sets count and adds a tag to the existing list.