Bird
Raised Fist0

You wrote this runtime field script:

medium📝 Debug Q14 of Q15
Elasticsearch - Advanced Patterns
You wrote this runtime field script:
{
  "runtime_mappings": {
    "discounted_price": {
      "type": "double",
      "script": {
        "source": "emit(doc['price'].value * 0.9)"
      }
    }
  }
}

But the query fails with an error: Field [price] not found in doc. What is the likely cause?
ARuntime fields cannot use numeric types
BThe script syntax is incorrect
CThe <code>price</code> field is missing in some documents
DThe <code>discounted_price</code> field must be defined in mappings
Step-by-Step Solution
Solution:
  1. Step 1: Analyze error message

    Error says price field not found in document, meaning some docs lack this field.
  2. Step 2: Understand runtime field behavior

    Runtime scripts fail if they access missing fields without checks.
  3. Final Answer:

    The price field is missing in some documents -> Option C
  4. Quick Check:

    Missing field in doc causes runtime script error [OK]
Quick Trick: Check if all docs have fields used in runtime scripts [OK]
Common Mistakes:
MISTAKES
  • Assuming script syntax error without checking data
  • Thinking runtime fields require mapping changes
  • Ignoring missing field presence in documents

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes