Groovy parseText to json

I want to parse Text to json in groovy script
but get errors:

failed to load/compile script [my_script]

This is my_script.groovy file:

d=doc['data'].value
//d='data=%7B%22request%22%3A%7B%22model%22%3A%22Score%22%2C%22action%22%3A%22getSignInScoreEx%22%2C%22parameters%22%3A%7B%22uid%22%3A%22108043431%22%7D%7D%7D'
//path='request.parameters.uid'
//val='108043431'

ebody=d.substring(5);
body=java.net.URLDecoder.decode(ebody,"UTF-8");
json=new groovy.json.JsonSlurper().parseText(body);
paths=path.split('\.')

obj = json
for(String p : paths) {
obj=obj[p]
}
if(obj==val) {
return true
} else {
return false
}

after some debug,problem may comes from "json=new groovy.json.JsonSlurper().parseText(body);"

anyone can help me? thx

(ElasticSearver version: 2.4.1)

Jsonslurper is not supported iirc.

What class should I use instead?

thx!
after google,i found a solution:

  1. drop http://central.maven.org/maven2/org/codehaus/groovy/groovy-json/2.4.6/groovy-json-2.4.6.jar in the ${ELASTICSEARCH_HOME}/modules/lang-groovy/ directory for it to work.
  2. add permissions to file: ${ELASTICSEARCH_HOME}/modules/lang-groovy/plugin-security.policy
    permission org.elasticsearch.script.ClassPermission "groovy.json.JsonSlurper";

it works only in:
./bin/elasticsearch -d --security.manager.enabled
es version:2.4.2

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