The elasticsearch painless script is essentially a groovy script which is compiled and run on JVM level.
You can write Java code in groovy painless script.
The trim() method of String class is used for trimming the data. Here is simple example:
POST /testing_index/doc/_update_by_query { "script": { "lang": "painless", "source": """ ctx._source.first_name = ctx._source.first_name.trim(); """ } }
Thanks