Ondrej Burkert
Ondrej Burkert

Reputation: 7262

ElasticSearch script_lang not supported [groovy]

I'm upgrading ElasticSearch from 1.2 to 2.2. I dug successfully through quite some breaking API changes. I found that groovy scripts in script_score don't work. I enabled dynamic scripting by turning on

script.inline=true
script.indexed=true

I included groovy-all 2.4.6. I also added jna and mustache to not see any exceptions when the embedded ElasticSearch starts.

The configuration of my embedded server is:

        ESLoggerFactory.setDefaultFactory(new Slf4jESLoggerFactory());
        Settings settings = Settings.builder()
                .put("node.name" ,getName())
                .put("path.home", "/tmp/elastic-search/home")
                .put("path.shared_data", /tmp/elastic-search")
                .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, "1")
                .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, "0")
                .put("action.auto_create_index", "0")
                .put("index.gateway.type", "none")
                .put("script.inline", true)
                .put("script.indexed", true)
                .put("action.destructive_requires_name", false)
                .build();

        node = nodeBuilder().clusterName(clusterName).settings(settings).node();

Then I execute a query which contains a snippet under function_score/functions which looks loke:

        "filter" : {
          "exists" : {
            "field" : "transactionCount"
          }
        },
        "script_score" : {
          "script" : {
            "inline" : "doc['transactionCount'].value/10.0"
          }
        }

The execution throws:

Caused by: org.elasticsearch.index.query.QueryParsingException: script_score the script could not be loaded
...
Caused by: java.lang.IllegalArgumentException: script_lang not supported [groovy]
    at  org.elasticsearch.script.ScriptService.getScriptEngineServiceForLang(ScriptService.java:211)

When debugging I saw in ScriptModule that the script engine for Groovy is missing. Only the native and the mustache ones are present.

Any tip is very welcome:)

Upvotes: 3

Views: 6763

Answers (2)

Pavan Reddy
Pavan Reddy

Reputation: 31

Add the below 3 entries in the elasticsearch.yml file. It will resolve the issue.

index.max_result_window: 2147483647 
script.engine.groovy.inline.aggs: on 
script.engine.groovy.inline.search: on

Upvotes: 0

Jérémie B
Jérémie B

Reputation: 11022

In ElasticSearch 2.2, the scripts engines have been externalized: they are now plugins, which you can install on demand. Plugins are discovered by scanning the plugins folder.

If you use an embedded node, you have two choices:

  • Use this plugins folder, and copy the lang-groovy-2.2.0.jar in this folder
  • Explicitly register the Groovy plugins when you create your node

In my project, I use the 2nd case: ElasticSearch is embedded in an osgi container, and I wanted to discover the plugins through a classical classpath scanning. To do this kind of things, you must override Node:

class ConfigurableNode extends Node {
  public ConfigurableNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins) {
    super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), 
      Version.CURRENT, 
      classpathPlugins);
  }
}

and you create your node with :

Node node = new ConfigurableNode(nodeBuilder()
  .clusterName(clusterName)
  .settings(settings)
  .getSettings(), 
    Arrays.asList(GroovyPlugin.class)); 

It's not pretty but I didn't find a method more elegant in v2.2

Upvotes: 8

Related Questions