Bird
Raised Fist0

You want to create a runtime field status that returns "adult" if age ≥ 18, otherwise "minor". Which painless script correctly implements this logic?

hard🚀 Application Q15 of Q15
Elasticsearch - Advanced Patterns
You want to create a runtime field status that returns "adult" if age ≥ 18, otherwise "minor". Which painless script correctly implements this logic?
A"emit(doc['age'].value >= 18 ? 'adult' : 'minor')"
B"if (doc['age'].value >= 18) { return 'adult' } else { return 'minor' }"
C"emit(doc['age'] >= 18 ? 'adult' : 'minor')"
D"emit(doc['age'].value > 18 ? 'adult' : 'minor')"
Step-by-Step Solution
Solution:
  1. Step 1: Check correct painless syntax for runtime fields

    Runtime fields use emit() to output values; accessing field value requires doc['age'].value.
  2. Step 2: Verify conditional logic

    "emit(doc['age'].value >= 18 ? 'adult' : 'minor')" uses ternary operator with >= 18 and emits 'adult' or 'minor' correctly.
  3. Final Answer:

    "emit(doc['age'].value >= 18 ? 'adult' : 'minor')" -> Option A
  4. Quick Check:

    emit() + ternary + doc['age'].value = correct [OK]
Quick Trick: Use emit() with ternary and doc['field'].value for conditions [OK]
Common Mistakes:
MISTAKES
  • Using return instead of emit() in runtime fields
  • Accessing doc['age'] without .value
  • Using > instead of >= changing logic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes