Default scripting language in Kibana is Lucene Expressions, so you have to specify {"script" : "blah", "lang" : "groovy"} in your JSON input.
You can also use static scripts, if you don't want to use dynamic - more on that here: Calling groovy script from Kibana