The default language for Kibana scripted fields is Lucene expressions, which can only work with integers at this time.
You can instead use Groovy scripts, which can operate on strings, but take care to do so in a secure manner (dynamic scripts are insecure, so you must use static scripts). More on that in this thread: Calling groovy script from Kibana