Groovy ElsticSearch script

Hi guys,
I'm making a simple script to add information to documents.

My first aproximation to solve my problem is based in a local script. I
need to parse it and before add simple field to the documents.

My problem is making
import groovy.json.JsonSlurper

def jsonFile = new File("./custom_data.json");
def json = new JsonSlurper().parseText(jsonFile.text);
def ident="id1";

json[ident];

ElasticSearch show the next error when i save the script:
java.lang.SecurityException: Importing [groovy.json.JsonSlurper] is not
allowed
at
org.codehaus.groovy.control.customizers.SecureASTCustomizer.assertImportIsAllowed(SecureASTCustomizer.java:609)
at
org.codehaus.groovy.control.customizers.SecureASTCustomizer.call(SecureASTCustomizer.java:531)
at
org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1047)
at
org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:583)
at
org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:561)
at
org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:538)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:286)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:259)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:245)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:203)
at
org.elasticsearch.script.groovy.GroovyScriptEngineService.compile(GroovyScriptEngineService.java:119)
at
org.elasticsearch.script.ScriptService$ScriptChangesListener.onFileInit(ScriptService.java:548)
at
org.elasticsearch.script.ScriptService$ScriptChangesListener.onFileChanged(ScriptService.java:581)
at
org.elasticsearch.watcher.FileWatcher$FileObserver.onFileChanged(FileWatcher.java:261)
at
org.elasticsearch.watcher.FileWatcher$FileObserver.checkAndNotify(FileWatcher.java:112)
at
org.elasticsearch.watcher.FileWatcher$FileObserver.updateChildren(FileWatcher.java:197)
at
org.elasticsearch.watcher.FileWatcher$FileObserver.checkAndNotify(FileWatcher.java:98)
at
org.elasticsearch.watcher.FileWatcher.doCheckAndNotify(FileWatcher.java:52)
at
org.elasticsearch.watcher.AbstractResourceWatcher.checkAndNotify(AbstractResourceWatcher.java:43)
at
org.elasticsearch.watcher.ResourceWatcherService$ResourceMonitor.run(ResourceWatcherService.java:180)
at
org.elasticsearch.threadpool.ThreadPool$LoggingRunnable.run(ThreadPool.java:489)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

1 error
]
at
org.elasticsearch.script.groovy.GroovyScriptEngineService.compile(GroovyScriptEngineService.java:124)
at
org.elasticsearch.script.ScriptService$ScriptChangesListener.onFileInit(ScriptService.java:548)
at
org.elasticsearch.script.ScriptService$ScriptChangesListener.onFileChanged(ScriptService.java:581)
at
org.elasticsearch.watcher.FileWatcher$FileObserver.onFileChanged(FileWatcher.java:261)
at
org.elasticsearch.watcher.FileWatcher$FileObserver.checkAndNotify(FileWatcher.java:112)
at
org.elasticsearch.watcher.FileWatcher$FileObserver.updateChildren(FileWatcher.java:197)
at
org.elasticsearch.watcher.FileWatcher$FileObserver.checkAndNotify(FileWatcher.java:98)
at
org.elasticsearch.watcher.FileWatcher.doCheckAndNotify(FileWatcher.java:52)
at
org.elasticsearch.watcher.AbstractResourceWatcher.checkAndNotify(AbstractResourceWatcher.java:43)
at
org.elasticsearch.watcher.ResourceWatcherService$ResourceMonitor.run(ResourceWatcherService.java:180)
at
org.elasticsearch.threadpool.ThreadPool$LoggingRunnable.run(ThreadPool.java:489)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

Here all the non empty lines in elasticsearch.yaml:
cat /etc/elasticsearch/elasticsearch.yml |grep -v ^#|grep -v ^$

node.name: "my-elasticsearch"
script.groovy.sandbox.enabled: true
script.auto_reload_enabled: 15s
script.groovy.sandbox.package_whitelist: "groovy.json"
script.groovy.sandbox.class_whitelist: "JsonSlurper"
script.groovy.sandbox.receiver_whitelist: "parseText"
http.cors.allow-origin: "/.*/"
http.cors.enabled: true

I tried all combinations with package_whitelist, class_whitelist and
receiver_whitelist.

Could Some one show me how to import it?
Regards

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/6f6b127e-2692-4522-9019-a49e5b8e860a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I'm having a similar problem. Were you able to get this to work? Thanks!

On Friday, February 13, 2015 at 4:18:06 AM UTC-8, Sergio Soto Núñez wrote:

Hi guys,
I'm making a simple script to add information to documents.

My first aproximation to solve my problem is based in a local script. I
need to parse it and before add simple field to the documents.

My problem is making
import groovy.json.JsonSlurper

def jsonFile = new File("./custom_data.json");
def json = new JsonSlurper().parseText(jsonFile.text);
def ident="id1";

json[ident];

Elasticsearch show the next error when i save the script:
java.lang.SecurityException: Importing [groovy.json.JsonSlurper] is not
allowed
at
org.codehaus.groovy.control.customizers.SecureASTCustomizer.assertImportIsAllowed(SecureASTCustomizer.java:609)
at
org.codehaus.groovy.control.customizers.SecureASTCustomizer.call(SecureASTCustomizer.java:531)
at
org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1047)
at
org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:583)
at
org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:561)
at
org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:538)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:286)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:259)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:245)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:203)
at
org.elasticsearch.script.groovy.GroovyScriptEngineService.compile(GroovyScriptEngineService.java:119)
at
org.elasticsearch.script.ScriptService$ScriptChangesListener.onFileInit(ScriptService.java:548)
at
org.elasticsearch.script.ScriptService$ScriptChangesListener.onFileChanged(ScriptService.java:581)
at
org.elasticsearch.watcher.FileWatcher$FileObserver.onFileChanged(FileWatcher.java:261)
at
org.elasticsearch.watcher.FileWatcher$FileObserver.checkAndNotify(FileWatcher.java:112)
at
org.elasticsearch.watcher.FileWatcher$FileObserver.updateChildren(FileWatcher.java:197)
at
org.elasticsearch.watcher.FileWatcher$FileObserver.checkAndNotify(FileWatcher.java:98)
at
org.elasticsearch.watcher.FileWatcher.doCheckAndNotify(FileWatcher.java:52)
at
org.elasticsearch.watcher.AbstractResourceWatcher.checkAndNotify(AbstractResourceWatcher.java:43)
at
org.elasticsearch.watcher.ResourceWatcherService$ResourceMonitor.run(ResourceWatcherService.java:180)
at
org.elasticsearch.threadpool.ThreadPool$LoggingRunnable.run(ThreadPool.java:489)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

1 error
]
at
org.elasticsearch.script.groovy.GroovyScriptEngineService.compile(GroovyScriptEngineService.java:124)
at
org.elasticsearch.script.ScriptService$ScriptChangesListener.onFileInit(ScriptService.java:548)
at
org.elasticsearch.script.ScriptService$ScriptChangesListener.onFileChanged(ScriptService.java:581)
at
org.elasticsearch.watcher.FileWatcher$FileObserver.onFileChanged(FileWatcher.java:261)
at
org.elasticsearch.watcher.FileWatcher$FileObserver.checkAndNotify(FileWatcher.java:112)
at
org.elasticsearch.watcher.FileWatcher$FileObserver.updateChildren(FileWatcher.java:197)
at
org.elasticsearch.watcher.FileWatcher$FileObserver.checkAndNotify(FileWatcher.java:98)
at
org.elasticsearch.watcher.FileWatcher.doCheckAndNotify(FileWatcher.java:52)
at
org.elasticsearch.watcher.AbstractResourceWatcher.checkAndNotify(AbstractResourceWatcher.java:43)
at
org.elasticsearch.watcher.ResourceWatcherService$ResourceMonitor.run(ResourceWatcherService.java:180)
at
org.elasticsearch.threadpool.ThreadPool$LoggingRunnable.run(ThreadPool.java:489)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

Here all the non empty lines in elasticsearch.yaml:
cat /etc/elasticsearch/elasticsearch.yml |grep -v ^#|grep -v ^$

node.name: "my-elasticsearch"
script.groovy.sandbox.enabled: true
script.auto_reload_enabled: 15s
script.groovy.sandbox.package_whitelist: "groovy.json"
script.groovy.sandbox.class_whitelist: "JsonSlurper"
script.groovy.sandbox.receiver_whitelist: "parseText"
http.cors.allow-origin: "/.*/"
http.cors.enabled: true

I tried all combinations with package_whitelist, class_whitelist and
receiver_whitelist.

Could Some one show me how to import it?
Regards

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/8dc15418-c5f7-4450-a0cd-34a129b452f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.