Elasticsearch scripting: Invoke custom script from plugin

If we defined native script in plugin: com.test.nativescript.TestScript, can we invoke that package inside another groovy script and create new instance ?

Ex:
inside config/scripts/test.groovy:

import  com.test.nativescript.TestScript;

def testScript = new TestScript();

Result: "startup failed:\r\nc78a82bc96ca7751e83e256b4ee0c322cda13bea: 1: unable to resolve com.test.nativescript.TestScript"

Someone help me please, I really need it.

The error you get seems to say that you cannot do this. May I ask you what you intend to do? You already wrote a script plugin that you can use, why would another script need to use it?

@javanna: this is common script which I use cross multiple scripts.
Look like it's impossible due to security check.

That's what I thought, but again I am not sure why you would need that, maybe you can refactor your scripts into a single one, or provide a better explanation of why so we can help you.

Cheers
Luca

@javanna: Thanks so much for your help.
My scenario:
Previously with ES 1.5, i have native script to calculate total amount (logic is very complex). then I have multiple scripts run with facet plugin using map-reduce approach. Inside those scripts, get total script to calculate amount, then use it for some logic:

compiledScript = scriptService.compile('native','amount', null);
executableScript = scriptService.executable(compiledScript, param);
amount = executableScript.run(doc())

Now I want to upgrade to ES 2.0 without facet support, so I try to use aggregation. But due to security problem, now no way to access native to do that.

I tried to switch solution, build other native which used to call groovy map-reduce scripts but still stuck: https://github.com/elastic/elasticsearch/issues/17461
Even with native, I cannot access ScriptService, only GroovyScriptEngineService and couldn't invoke File Scripts.

Did I do anything wrong or we cannot do it ?
Please advice.
Thanks.

At first glance I would say that you are doing too much from within a script and most of this logic should be done outside of elasticsearch instead. When scripts become too complex they slow searches down and become very complex to maintain. And the fact that you have multiple scripts that depend on each other makes it even worse I think. We did work a lot on security from 2.0 on, so I am not surprised that you cannot do anymore what you used to be able to do in 1.x from a script.

It would probably be a good idea to try and take out of scripts some of your complex logic and do this processing work outside of elasticsearch.

1 Like

Thank for your help. I'm clear about that problem.