# ScriptException\[dynamic scripting for \[groovy\] disabled\] with Java API

**URL:** <https://discuss.elastic.co/t/scriptexception-dynamic-scripting-for-groovy-disabled-with-java-api/25699>\
**Category:** Elasticsearch\
**Created:** [July 16, 2015, 7:51am UTC](https://discuss.elastic.co/t/scriptexception-dynamic-scripting-for-groovy-disabled-with-java-api/25699 "2015-07-16T07:51:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryan686806](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@ryan686806](https://discuss.elastic.co/u/ryan686806)\
**Post date:** [July 16, 2015, 7:51am UTC](https://discuss.elastic.co/t/scriptexception-dynamic-scripting-for-groovy-disabled-with-java-api/25699/1 "2015-07-16T07:51:03Z")

</div>

I am into troubles when i use elasticsearch 1.5.2 by javaAPI,  
this is my code:

```
 Settings settings = ImmutableSettings.settingsBuilder()
			.put("client.transport.ignore_cluster_name", true)
			.put("client.transport.sniff", true)
			.put(GroovyScriptEngineService.GROOVY_SCRIPT_SANDBOX_ENABLED, true)
			.build();
	Client client = null;
	try{
	client = new TransportClient(settings)
			.addTransportAddress(new InetSocketTransportAddress("192.168.60.221", 9300));
              ...

SearchResponse response = client.prepareSearch("shanghai")
	        .setTypes("gcjl_hphminfo")
	        .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
	        .setQuery(QueryBuilders.termQuery("clpp", "48")) // Query
	        .setPostFilter(FilterBuilders.scriptFilter("doc['clnk'].value | clnk").addParam("clnk", 1)) // Filter
	        .setFrom(0).setSize(100).setExplain(true)
	        .execute()
	        .actionGet();
	 '

```

it is the exception:

```
: Failed to execute phase [dfs], all shards failed; shardFailures {[n5Awr3SoRPuFRJO3Uz3ICg][shanghai][0]: SearchParseException[[shanghai][0]: query[clpp:48],from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"query":{"term":{"clpp":"48"}},"post_filter":{"script":{"script":"doc['clnk'].value + clnk","params":{"clnk":1}}},"explain":true}]]]; nested: ScriptException[dynamic scripting for [groovy] disabled]; }{[n5Awr3SoRPuFRJO3Uz3ICg][shanghai][1]: SearchParseException[[shanghai][1]: query[clpp:48],from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"query":{"term":{"clpp":"48"}},"post_filter":{"script":{"script":"doc['clnk'].value + clnk","params":{"clnk":1}}},"explain":true}]]]; nested: ScriptException[dynamic scripting for [groovy] disabled]; }{[n5Awr3SoRPuFRJO3Uz3ICg][shanghai][2]: SearchParseException[[shanghai][2]: query[clpp:48],from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"query":{"term":{"clpp":"48"}},"post_filter":{"script":{"script":"doc['clnk'].value + clnk","params":{"clnk":1}}},"explain":true}]]]; nested: ScriptException[dynamic scripting for [groovy] disabled]; }{[n5Awr3SoRPuFRJO3Uz3ICg][shanghai][3]: SearchParseException[[shanghai][3]: query[clpp:48],from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"query":{"term":{"clpp":"48"}},"post_filter":{"script":{"script":"doc['clnk'].value + clnk","params":{"clnk":1}}},"explain":true}]]]; nested: ScriptException[dynamic scripting for [groovy] disabled]; }{[n5Awr3SoRPuFRJO3Uz3ICg][shanghai][4]: SearchParseException[[shanghai][4]: query[clpp:48],from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"query":{"term":{"clpp":"48"}},"post_filter":{"script":{"script":"doc['clnk'].value + clnk","params":{"clnk":1}}},"explain":true}]]]; nested: ScriptException[dynamic scripting for [groovy] disabled]; }

```

I have setted "script.disable\_dynamic: false" in elasticsearch.yml,but it is not afftected,so,what should i do in order to let it work rightly?

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [July 16, 2015, 7:56am UTC](https://discuss.elastic.co/t/scriptexception-dynamic-scripting-for-groovy-disabled-with-java-api/25699/2 "2015-07-16T07:56:41Z")

</div>

Did you set `script.disable_dynamic: false` on all of your nodes? Did you restart Elasticsearch after making this change?

---

<div class="post-metadata">

**Author:** ![ryan686806](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@ryan686806](https://discuss.elastic.co/u/ryan686806)\
**Post date:** [July 16, 2015, 8:02am UTC](https://discuss.elastic.co/t/scriptexception-dynamic-scripting-for-groovy-disabled-with-java-api/25699/3 "2015-07-16T08:02:00Z")

</div>

I have restart it three times after i set script.disable\_dynamic: false, and i run it in single node ,the version is 1.5.2

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [July 16, 2015, 8:12am UTC](https://discuss.elastic.co/t/scriptexception-dynamic-scripting-for-groovy-disabled-with-java-api/25699/4 "2015-07-16T08:12:49Z")

</div>

Ok, how did you install your node? from the zip/tarball, the rpm or the deb? If you installed through the rpm or the deb I believe the default location for `elasticsearch.yml` is in `/etc/elasticsearch` so you would need to update it there rather than in the `$ES_HOME/config` directory

---

<div class="post-metadata">

**Author:** ![ryan686806](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@ryan686806](https://discuss.elastic.co/u/ryan686806)\
**Post date:** [July 16, 2015, 8:40am UTC](https://discuss.elastic.co/t/scriptexception-dynamic-scripting-for-groovy-disabled-with-java-api/25699/5 "2015-07-16T08:40:18Z")

</div>

I install it through zip in CentOS 6.2,i update it in the $ES\_HOME/config directory, try many ways to suit it ,but all failed!

---

<div class="post-metadata">

**Author:** ![ryan686806](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@ryan686806](https://discuss.elastic.co/u/ryan686806)\
**Post date:** [July 16, 2015, 9:31am UTC](https://discuss.elastic.co/t/scriptexception-dynamic-scripting-for-groovy-disabled-with-java-api/25699/6 "2015-07-16T09:31:19Z")

</div>

which another way to achive the goal except that I point ? If it still bad,i have to try another.

---

<div class="post-metadata">

**Author:** ![ryan686806](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@ryan686806](https://discuss.elastic.co/u/ryan686806)\
**Post date:** [July 16, 2015, 9:49am UTC](https://discuss.elastic.co/t/scriptexception-dynamic-scripting-for-groovy-disabled-with-java-api/25699/7 "2015-07-16T09:49:09Z")

</div>

I find the reason that it throws exception,when I press ^ to insert a space at begin of the script.disable\_dynamic: false,it works rightly,I forget the rule,now it is ok!  
thanks to colings86!

---

<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:** [July 6, 2017, 12:01am UTC](https://discuss.elastic.co/t/scriptexception-dynamic-scripting-for-groovy-disabled-with-java-api/25699/8 "2017-07-06T00:01:05Z")

</div>


