Painless scripting JSON functions


(Hitesh Baldaniya) #1

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.


(Mike Barretta) #2

@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


Slashes in a JSON field - can't visualize on sub-fields
(Hitesh Baldaniya) #3

Thanks Mike,

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


(Mike Barretta) #4

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.


(Hitesh Baldaniya) #5

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.


(Mike Barretta) #6

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


(system) #7

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