Painless scripting JSON functions

In Painless scripting how can I do JSON.parse and JSON.stringify?

I have kept JSON data in the single string field, but now I want to delete some of the fields. So I will be needing JSON functions.

@HDB there are no JSON parsing classes in the Painless API.

To do what you're considering, I think you'll want to re-index that data using Logstash to convert the string field into a JSON object using the JSON filter and dropping fields.

Logstash pipeline: Elasticsearch input --> JSON filter --> Elasticsearch output

Thanks Mike,

I am planning to use elastic-js scripting, will that work fine? Or any performance issues that we can face?

Do you mean using a javascript client library (like this or this)? No, I don't think that will do what you want since there will not (AFAIK) be general JSON-manipulation methods within it. However, you would be able to use regular javascript.

So, you'd use the ES.js client to query the data, use regular javascript to manipulate it (drop fields, etc), then use the client to push the results back.

I was pointing out for https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#_general_purpose_languages. To update documents will execute the script placed under config/scripts written in the javascript.

And, Will need to enable the language support in elastic service.

OK, but as heads up, the only language you'll be able to use for that
purpose in the upcoming v6.0 is our Painless scripting language. See
https://github.com/elastic/elasticsearch/issues/20129 and
https://www.elastic.co/guide/en/elasticsearch/reference/6.0/modules-scripting.html

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