Elasticsearch 5.2.0, embedded node, script_lang not supported [groovy]

Im migrating from Elasticsearch 2.1.1 to Elasticsearch 5.2.0. We have an existing integration test suite written against an embedded node & we are using groovy scripting. Ive updated the build an embedded node with ES 5.2.0 but i get the following error when running script queries against it:

Caused by: org.elasticsearch.transport.RemoteTransportException: [4xG7vRN][local[1]][indices:data/read/search[phase/query+fetch]]
Caused by: org.elasticsearch.index.query.QueryShardException: script_score: the script could not be loaded
	at org.elasticsearch.index.query.functionscore.ScriptScoreFunctionBuilder.doToFunction(ScriptScoreFunctionBuilder.java:100) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder.toFunction(ScoreFunctionBuilder.java:137) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.doToQuery(FunctionScoreQueryBuilder.java:304) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:97) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.search.rescore.QueryRescorerBuilder.build(QueryRescorerBuilder.java:172) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.search.SearchService.parseSource(SearchService.java:726) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.search.SearchService.createContext(SearchService.java:540) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:516) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:351) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.action.search.SearchTransportService$9.messageReceived(SearchTransportService.java:322) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.action.search.SearchTransportService$9.messageReceived(SearchTransportService.java:319) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:610) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:596) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-5.2.0.jar:5.2.0]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_131]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_131]
	at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_131]
Caused by: java.lang.IllegalArgumentException: script_lang not supported [groovy]
	at org.elasticsearch.script.ScriptService.getScriptEngineServiceForLang(ScriptService.java:189) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.script.ScriptService.compile(ScriptService.java:221) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.script.ScriptService.search(ScriptService.java:490) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.index.query.QueryShardContext.getSearchScript(QueryShardContext.java:349) ~[elasticsearch-5.2.0.jar:5.2.0]
	at org.elasticsearch.index.query.functionscore.ScriptScoreFunctionBuilder.doToFunction(ScriptScoreFunctionBuilder.java:97) ~[elasticsearch-5.2.0.jar:5.2.0]
	... 17 common frames omitted

This is the code im using to create my embedded node, i cant seem to get the right settings to pass to ES to turn on Groovy scripting. If someone can point me in the right direction here that would be great. I do have groovy in my classpath as well.

    /**
     * Use to create an embedded elasticsearch node for testing, look at the assumed defaults before using
     * this Node for purposes other than testing. If using this you will need the following dependencies:
     * <p>
     * testCompile 'org.codehaus.groovy:groovy-all:latestVersion'
     *
     * @param clusterName
     * @return
     */
    public static Node createEmbeddedNodeForTesting(String clusterName) {
        final String path = Files.createTempDir().getAbsolutePath();
        LOGGER.info("Creating embedded node data directories at [{}]", path);

        final Settings settings = Settings.builder()
                .put("http.enabled", false)
                .put("transport.type", "local")
                .put("cluster.name", clusterName)
                .put("client.transport.sniff", false)
                .put("path.data", String.format("%s/%s-data", path, clusterName))
                .put("path.home", String.format("%s/%s-home", path, clusterName))
                .put("node.data", "true")
                .put("script.legacy.default_lang", "groovy")
                .put("script.inline", true)
                .build();

        return new ConfigurableNode(
                settings,
                new ArrayList<>(0)
        );
    }

    /**
     * A configurable node which extends Node to allow specification of plugins to install/start for Embedded instances.
     * Plugins have to be in the classpath for startup.
     */
    private static final class ConfigurableNode extends Node {

        private ConfigurableNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins) {
            super(InternalSettingsPreparer.prepareEnvironment(settings, null),
                    classpathPlugins);
        }

    }

It seems like i have to add the Groovy plugin from org.elasticsearch.script.groovy but im not sure what module to import for that.

I have figured this out.

  1. You need to add .put("script.legacy.default_lang", "groovy") to the Elasticsearch settings for the node you are building.

  2. You need the GroovyPlugin.class available in the classpath. It seems like for Elasticsearch 5.2.0 the scripts module it not exported to Maven so i got around this by adding lang-groovy-5.2.0.jar, plugin-descriptor.properties and plugin-security.policy to a libs directory as per the image below and then adding compile fileTree(dir: '../libs', include: '*.*' to my build.gradle

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