# Script Engine with JAVA - elasticsearch-6.3.0

**URL:** https://discuss.elastic.co/t/script-engine-with-java-elasticsearch-6-3-0/146500
**Category:** Elasticsearch
**Created:** [August 29, 2018, 9:39am UTC](https://discuss.elastic.co/t/script-engine-with-java-elasticsearch-6-3-0/146500 "2018-08-29T09:39:52Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![moni15moni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/moni15moni/32/42311_2.png) [@moni15moni](https://discuss.elastic.co/u/moni15moni)
#### Post date: [August 29, 2018, 9:39am UTC](https://discuss.elastic.co/t/script-engine-with-java-elasticsearch-6-3-0/146500/1 "2018-08-29T09:39:52Z")

</div>

Hi

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(QueryShardContext.java:320)  
at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:303)  
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:724)  
at org.elasticsearch.search.SearchService.createContext(SearchService.java:575)  
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:551)  
at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:347)  
at org.elasticsearch.search.SearchService$2.onResponse(SearchService.java:333)  
... 9 more  
Caused by: java.lang.IllegalArgumentException: script\_lang not supported [native]

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

---

<div class="post-metadata">

### Author: ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)
#### Post date: [August 29, 2018, 8:21pm UTC](https://discuss.elastic.co/t/script-engine-with-java-elasticsearch-6-3-0/146500/2 "2018-08-29T20:21:46Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/modules-scripting-engine.html) to start.

---

<div class="post-metadata">

### Author: ![moni15moni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/moni15moni/32/42311_2.png) [@moni15moni](https://discuss.elastic.co/u/moni15moni)
#### Post date: [August 30, 2018, 6:22am UTC](https://discuss.elastic.co/t/script-engine-with-java-elasticsearch-6-3-0/146500/3 "2018-08-30T06:22:24Z")

</div>

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,

@Override  
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 {
    
@Override
public String getType() {
    return "expert_scripts";
}

@Override
public <T> T compile(String scriptName, String scriptSource, ScriptContext<T> context, Map<String, String> params) {        
    
    log.info("Script name: "+scriptName);
    log.info("scriptSource "+scriptSource);
    
    log.info("SearchScript.CONTEXT "+SearchScript.CONTEXT);
    
    if (context.equals(SearchScript.CONTEXT) == false) {
        throw new IllegalArgumentException(getType() + " scripts cannot be used for context [" + context.name + "]");
    }
    // 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

---

<div class="post-metadata">

### Author: ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)
#### Post date: [August 30, 2018, 6:17pm UTC](https://discuss.elastic.co/t/script-engine-with-java-elasticsearch-6-3-0/146500/4 "2018-08-30T18:17:53Z")

</div>

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.

---

<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: [September 27, 2018, 6:17pm UTC](https://discuss.elastic.co/t/script-engine-with-java-elasticsearch-6-3-0/146500/5 "2018-09-27T18:17:53Z")

</div>

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