# Scripts may be no longer than 16384 characters

**URL:** <https://discuss.elastic.co/t/scripts-may-be-no-longer-than-16384-characters/158178>\
**Category:** Elasticsearch\
**Created:** [November 26, 2018, 12:26pm UTC](https://discuss.elastic.co/t/scripts-may-be-no-longer-than-16384-characters/158178 "2018-11-26T12:26:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bfcshop](https://avatars.discourse-cdn.com/v4/letter/b/5f8ce5/32.png) [@bfcshop](https://discuss.elastic.co/u/bfcshop)\
**Post date:** [November 26, 2018, 12:26pm UTC](https://discuss.elastic.co/t/scripts-may-be-no-longer-than-16384-characters/158178/1 "2018-11-26T12:26:44Z")

</div>

I am using Elasticsearch on my Magento store and I found a problem when searching for product, but only for some search strings

Here is the error log:  
{"0":"{"error":{"root\_cause":[{"type":"script\_exception","reason":"compile error","script\_stack":,"script":"def s =  
def id = Long.toString(doc['id'].value); return s[id];","lang":"painless","caused\_by":{"type":"illegal\_argument\_exception","reason":"Scripts may be no longer than 16384 characters. The passed in script is 29931 characters. Consider using a plugin if a script longer than this length is a requirement."}}}}],"caused\_by":

Any Idea how to solve this?  
I am using Elasticsearch 6.5.1 on Centos7

---

<div class="post-metadata">

**Author:** ![Jack\_Conradson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_conradson/32/47236_2.png) [@Jack\_Conradson](https://discuss.elastic.co/u/Jack_Conradson)\
**Post date:** [November 26, 2018, 8:01pm UTC](https://discuss.elastic.co/t/scripts-may-be-no-longer-than-16384-characters/158178/2 "2018-11-26T20:01:58Z")

</div>

I just want to be sure the stack trace isn't hiding anything - would you please copy and paste the exact script that caused this? Thanks!

---

<div class="post-metadata">

**Author:** ![bfcshop](https://avatars.discourse-cdn.com/v4/letter/b/5f8ce5/32.png) [@bfcshop](https://discuss.elastic.co/u/bfcshop)\
**Post date:** [November 27, 2018, 9:09am UTC](https://discuss.elastic.co/t/scripts-may-be-no-longer-than-16384-characters/158178/3 "2018-11-27T09:09:10Z")

</div>

{"0":"{"error":{"root\_cause":[{"type":"script\_exception","reason":"compile error","script\_stack":,"script":"def s = ['23353':2383,'12157':2382,'12163':2381,'12166':2380,'20304':2379,'23535':2378,'12161'......,]; def id = Long.toString(doc['id'].value); return s[id];","lang":"painless"}],"type":"search\_phase\_execution\_exception","reason":"all shards failed","phase":"query","grouped":true,"failed\_shards":[{"shard":0,"index":"default\_product\_idx1","node":"tO4GMfe-QJ6joi\_GlhvV1A","reason":{"type":"query\_shard\_exception","reason":"script\_score: the script could not be loaded","index\_uuid":"k9ipkQZQRweLruAdHTIrSg","index":"default\_product\_idx1","caused\_by":{"type":"script\_exception","reason":"compile error","script\_stack":,"script":"def s = ['23353':2383,'12157':2382,'12163':2381,'12166':2380,'20304':2379,'23535':2378,'12161':2377,'12165'....]; def id = Long.toString(doc['id'].value); return s[id];","lang":"painless","caused\_by":{"type":"illegal\_argument\_exception","reason":"Scripts may be no longer than 16384 characters. The passed in script is 29931 characters. Consider using a plugin if a script longer than this length is a requirement."}}}}],"caused\_by":{"type":"script\_exception","reason":"compile error","script\_stack":,"script":"def s = ['23353':2383,'12157':2382,'12163':2381,'12166':2380,'20304':2379,'23535':2378,'12161':2377,...]; def id = Long.toString(doc['id'].value); return s[id];","lang":"painless","caused\_by":{"type":"illegal\_argument\_exception","reason":"Scripts may be no longer than 16384 characters. The passed in script is 29931 characters. Consider using a plugin if a script longer than this length is a requirement."}}},"status":400}","1":"#0 /home/bfcshop/public\_html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(279): Elasticsearch\Connections\Connection-\>process4xxError(Array, Array, Array)

---

<div class="post-metadata">

**Author:** ![Jack\_Conradson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_conradson/32/47236_2.png) [@Jack\_Conradson](https://discuss.elastic.co/u/Jack_Conradson)\
**Post date:** [November 27, 2018, 5:15pm UTC](https://discuss.elastic.co/t/scripts-may-be-no-longer-than-16384-characters/158178/4 "2018-11-27T17:15:53Z")

</div>

So, unfortunately, there is a hard limit for Painless scripts in 6.5 of 16834 characters. This will be reduced to a soft limit in 6.6 ([https://github.com/elastic/elasticsearch/pull/35184](https://github.com/elastic/elasticsearch/pull/35184)). The script in question appears that its generating some kind of data as part of the variable s. This data should either be passed in as part of params or needs to be reduced in overall size for the script to work.

---

<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:** [December 25, 2018, 5:16pm UTC](https://discuss.elastic.co/t/scripts-may-be-no-longer-than-16384-characters/158178/5 "2018-12-25T17:16:04Z")

</div>

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