Bird
Raised Fist0

You need to define a runtime field complete_name that joins first_name and last_name with a comma and space (", "). Which painless script correctly implements this?

hard🚀 Application Q8 of Q15
Elasticsearch - Advanced Patterns
You need to define a runtime field complete_name that joins first_name and last_name with a comma and space (", "). Which painless script correctly implements this?
A"source": "emit(doc['first_name'].value + ', ' + doc['last_name'].value)"
B"source": "emit(doc['first_name'].value + ' ' + doc['last_name'].value)"
C"source": "emit(doc['last_name'].value + ', ' + doc['first_name'].value)"
D"source": "emit(doc['first_name'].value + '-' + doc['last_name'].value)"
Step-by-Step Solution
Solution:
  1. Step 1: Understand the requirement

    The runtime field complete_name must concatenate first_name and last_name separated by a comma and a space.
  2. Step 2: Analyze each option

    "source": "emit(doc['first_name'].value + ', ' + doc['last_name'].value)" concatenates first_name + ', ' + last_name, which matches the requirement.
    "source": "emit(doc['first_name'].value + ' ' + doc['last_name'].value)" uses a space instead of a comma and space.
    "source": "emit(doc['last_name'].value + ', ' + doc['first_name'].value)" reverses the order.
    "source": "emit(doc['first_name'].value + '-' + doc['last_name'].value)" uses a hyphen instead of a comma and space.
  3. Final Answer:

    "source": "emit(doc['first_name'].value + ', ' + doc['last_name'].value)" correctly concatenates with a comma and space.
  4. Quick Check:

    Check the separator used between names [OK]
Quick Trick: Check string concatenation and separator carefully [OK]
Common Mistakes:
MISTAKES
  • Using wrong separator between fields
  • Reversing the order of concatenation
  • Forgetting to add space after comma

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes