How to "unicode_escape" decode a text with painless script?

I have messages with escaped unicode characters, e.g.

{\x22hostname\x22:\x22ea55b62367a9\x22,\x22address\x22:\x22172.18.0.4\x22,\x22components\x22:[{\x22name\x22:\x22engine-api\x22,\x22version\x22:\x221.0.9-12\x22},{\x22name\x22:\x22sample\x22,\x22version\x22:\x221.4.2\x22},{\x22name\x22:\x22api-server\x22,\x22version\x22:\x221.2.3-dev207\x22}],\x22database\x22:{\x22createdAt\x22:\x222017-10-27T06:45:09.628\x22,\x22databaseName\x22:\x22generic\x22,\x22dataIdentifier\x22:\x22fO2iOtkd\x22},\x22titlesByLanguage\x22:
{\x22de\x22:\x22Windschutzscheibe\x22,\x22en\x22:\x22Windshield\x22,\x22en_lower\x22:\x22windshield\x22,\x22de_lower\x22:\x22windschutzscheibe\x22}}

I am writing a script processor to construct a Ingest node pipeline in ES with Painless. I want to convert such messages to its normal JSON expression. It's pretty trivial in Ruby as I assign such kind of strings to a Ruby string object, it will automatically change to:

"{\"hostname\":\"ea55b62367a9\",\"address\":\"172.18.0.4\",\"components\":[{\"name\":\"engine-api\",\"version\":\"1.0.9-12\"},{\"name\":\"sample\",\"version\":\"1.4.2\"},{\"name\":\"api-server\",\"version\":\"1.2.3-dev207\"}],\"database\":{\"createdAt\":\"2017-10-27T06:45:09.628\",\"databaseName\":\"generic\",\"dataIdentifier\":\"fO2iOtkd\"},\"titlesByLanguage\":\n{\"de\":\"Windschutzscheibe\",\"en\":\"Windshield\",\"en_lower\":\"windshield\",\"de_lower\":\"windschutzscheibe\"}}"

which is fairly easy for the next processors like JSON processor to further filter. But with Painless, how can I do this conversion? It's really painful with painless.

Thanks a lot!

p.s. the version of ES I am using: 6.0.0

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.