Complete the code to define a runtime field that calculates the length of the "message" field.
{
"runtime_mappings": {
"message_length": {
"type": "long",
"script": {
"source": "emit(doc['message'].value.[1])"
}
}
}
}The length() method returns the length of a string in painless scripts used in runtime fields.
Complete the code to create a runtime field that extracts the first 3 characters of the "user" field.
{
"runtime_mappings": {
"user_prefix": {
"type": "keyword",
"script": {
"source": "emit(doc['user'].value.[1](0, 3))"
}
}
}
}The substring method extracts a part of a string between two indices in painless scripts.
Fix the error in the runtime field script to correctly convert the "age" field to a string.
{
"runtime_mappings": {
"age_str": {
"type": "keyword",
"script": {
"source": "emit(doc['age'].value.[1]())"
}
}
}
}The toString() method converts a number to its string representation in painless scripts.
Fill both blanks to create a runtime field that checks if the "status" field equals "active" and emits 1 if true, else 0.
{
"runtime_mappings": {
"is_active": {
"type": "long",
"script": {
"source": "if (doc['status'].value [1] '[2]') { emit(1) } else { emit(0) }"
}
}
}
}The equality operator == checks if the field value equals the string 'active'.
Fill all three blanks to create a runtime field that emits the uppercase version of the "city" field only if its length is greater than 5.
{
"runtime_mappings": {
"city_upper": {
"type": "keyword",
"script": {
"source": "if (doc['city'].value.[1]() [2] 5) { emit(doc['city'].value.[3]()) }"
}
}
}
}The length() method gets the string length, > compares it to 5, and toUpperCase() converts the string to uppercase.