Thanks Joe!
I am trying to use path.split('_') as you suggested but haven't been able to get it right. My idea is to use this same approach for the different elements of the array. For instance:
def client = "";
def path = doc[''myfield.keyword].value;
if (...)
{client = path.split('_')[1];} else {client="none";}
return client
However, I keep getting the following error:
"lang": "painless", "caused_by": {"type":"illegal_argument_exception","reason":"dynamic method [java.lang.String, split/1] not found}"}.