Script Engine with JAVA - elasticsearch-6.3.0


Currently I am migrating elasticsearch-6.3.0 ,part of that Have to change script changes to Script Engine.
I have written the script using Native language ,java
The following syntax i am using to pass the values

Added the following in elasticsearch.yml script.allowed_types: inline

Script name is "country_script" ,lang is "native"

Map params = new HashMap();
            params.put("countryCode", srcCountryCode);
            params.put("isSourceCountry", true);
            Script script = new Script(ScriptType.INLINE, "native", "country_script", params);

But i am getting the following exceptions,

; nested: IllegalArgumentException[script_lang not supported [native]];
at org.elasticsearch.index.query.QueryShardContext.toQuery(
at org.elasticsearch.index.query.QueryShardContext.toQuery(
... 9 more
Caused by: java.lang.IllegalArgumentException: script_lang not supported [native]

Wht's wrong with the above syntax, any one please

What version of elasticsearch were you previously using? Native scripts went away in 6.0.0 (as did "inline" iirc, which is now "source"). You need to convert them to script engines (which you mentioned, but you I don't see any code for your engine mentioned). Try looking at creating an advanced script with script engines documentation to start.

Thanks for your response ,

Previously i have used elasticsearch-5.1.1 , now i have tried to use script engine the code with 6.3.0 follows,

public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) {
return new MyExpertScriptEngine();

/** An example {@link ScriptEngine} that uses Lucene segment details to implement pure document frequency scoring. */
// tag::expert_engine
private static class MyExpertScriptEngine implements ScriptEngine {
public String getType() {
    return "expert_scripts";

public <T> T compile(String scriptName, String scriptSource, ScriptContext<T> context, Map<String, String> params) {        "Script name: "+scriptName);"scriptSource "+scriptSource);"SearchScript.CONTEXT "+SearchScript.CONTEXT);
    if (context.equals(SearchScript.CONTEXT) == false) {
        throw new IllegalArgumentException(getType() + " scripts cannot be used for context [" + + "]");
    // we use the script "source" as the script identifier
    if ("pure_df".equals(scriptSource)) {
        SearchScript.Factory factory = (p, lookup) -> new SearchScript.LeafFactory() {
            final String field;
            final String term;
            .... etc}

IS there any sample java api to pass the inputs to script engine.

  1. What we have to define in lang,If i am not wrong we have to provide native(Java)

  2. Instead of script.inline where we have to mention the source, hope that's also in elasticsearch.yml

There aren't any java api examples, that I know of. You would need to use expert_scripts as the lang (this is the "type" of the script engine). I'm not sure what you mean by your second question.

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