Return first/last/mid characters of a keyword field

I have a field account name that has string values with spaces. I would like to return the first 5 and last 4 characters of each value in this field in a runtime painless field. how can this be done? thanks

Just use the substring method on the value, so something like this should work:

String desc = doc['desc.keyword'].value;
emit(desc.substring(desc.length() - 5))

1 Like

thank you!!