Challenge - 5 Problems
Runtime Fields Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a runtime script field calculation
What is the output of the following runtime field script when applied to a document with
price = 100 and tax = 0.15?Elasticsearch
{
"runtime_mappings": {
"total_price": {
"type": "double",
"script": {
"source": "emit(doc['price'].value * (1 + doc['tax'].value))"
}
}
}
}Attempts:
2 left
💡 Hint
Remember the formula for total price including tax is price * (1 + tax).
✗ Incorrect
The script multiplies the price (100) by 1 plus the tax rate (0.15), resulting in 100 * 1.15 = 115.0.
❓ Predict Output
intermediate2:00remaining
Runtime field with conditional logic output
Given the runtime field script below, what value will it emit for a document with
status = "active"?Elasticsearch
{
"runtime_mappings": {
"status_flag": {
"type": "keyword",
"script": {
"source": "if (doc['status'].value == 'active') { emit('1') } else { emit('0') }"
}
}
}
}Attempts:
2 left
💡 Hint
Check the condition comparing the status field value.
✗ Incorrect
The script checks if the status is 'active' and emits '1' if true, otherwise '0'. Since status is 'active', it emits '1'.
❓ Predict Output
advanced2:00remaining
Output of runtime field script with array field
What will the runtime field script emit for a document where
scores = [10, 20, 30]?Elasticsearch
{
"runtime_mappings": {
"max_score": {
"type": "long",
"script": {
"source": "emit(Collections.max(doc['scores'].values))"
}
}
}
}Attempts:
2 left
💡 Hint
The script uses Collections.max to find the highest value in the scores array.
✗ Incorrect
The script finds the maximum value in the scores array [10, 20, 30], which is 30.
❓ Predict Output
advanced2:00remaining
Runtime field script error type
What error will occur when running this runtime field script if the document does NOT have the
discount field?Elasticsearch
{
"runtime_mappings": {
"final_price": {
"type": "double",
"script": {
"source": "emit(doc['price'].value * (1 - doc['discount'].value))"
}
}
}
}Attempts:
2 left
💡 Hint
Accessing a missing field's value causes a null reference error.
✗ Incorrect
If the discount field is missing, accessing doc['discount'].value causes a NullPointerException in the script.
🧠 Conceptual
expert3:00remaining
Number of runtime fields created by this mapping
Given the following runtime_mappings configuration, how many runtime fields will be created?
Elasticsearch
{
"runtime_mappings": {
"field1": { "type": "keyword", "script": { "source": "emit('a')" } },
"field2": { "type": "long", "script": { "source": "emit(1)" } },
"field3": { "type": "double", "script": { "source": "emit(1.0)" } },
"field4": { "type": "boolean", "script": { "source": "emit(true)" } },
"field5": { "type": "date", "script": { "source": "emit(params._source['date_field'])" } }
}
}Attempts:
2 left
💡 Hint
Count each runtime field defined under runtime_mappings.
✗ Incorrect
There are 5 runtime fields defined: field1, field2, field3, field4, and field5.