# Groovy ElsticSearch script

**URL:** <https://discuss.elastic.co/t/groovy-elsticsearch-script/22152>\
**Category:** Elasticsearch\
**Created:** [February 13, 2015, 12:18pm UTC](https://discuss.elastic.co/t/groovy-elsticsearch-script/22152 "2015-02-13T12:18:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergio\_Soto\_Nunez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sergio_soto_nunez/32/902_2.png) [@Sergio\_Soto\_Nunez](https://discuss.elastic.co/u/Sergio_Soto_Nunez)\
**Post date:** [February 13, 2015, 12:18pm UTC](https://discuss.elastic.co/t/groovy-elsticsearch-script/22152/1 "2015-02-13T12:18:06Z")

</div>

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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/6f6b127e-2692-4522-9019-a49e5b8e860a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Julia\_Neidert](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@Julia\_Neidert](https://discuss.elastic.co/u/Julia_Neidert)\
**Post date:** [March 31, 2015, 8:56pm UTC](https://discuss.elastic.co/t/groovy-elsticsearch-script/22152/2 "2015-03-31T20:56:14Z")

</div>

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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/8dc15418-c5f7-4450-a0cd-34a129b452f3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:22am UTC](https://discuss.elastic.co/t/groovy-elsticsearch-script/22152/3 "2017-07-06T00:22:36Z")

</div>


