Tried providing explicit cast, this is the exception
"type" : "class_cast_exception",
"reason" : "Cannot cast from [java.lang.String] to [long].
"source": """
long msglen = "doc['message.keyword'].value.length()";
return (long) msglen;
"""
"source": """
double msglen = "doc['message.keyword'].value.length()";
return (long) msglen;
"""