How to create a conditional scripted field in Kibana

There is some info on how to do indicate you are using Groovy here with static scripts: Calling groovy script from Kibana

Alternatively, you can enable dynamic groovy (though I wouldn't recommend it, as it's insecure).