# Problem with Preloaded Scripts file size

**URL:** <https://discuss.elastic.co/t/problem-with-preloaded-scripts-file-size/5967>\
**Category:** Elasticsearch\
**Created:** [November 24, 2011, 5:17pm UTC](https://discuss.elastic.co/t/problem-with-preloaded-scripts-file-size/5967 "2011-11-24T17:17:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alsab](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@alsab](https://discuss.elastic.co/u/alsab)\
**Post date:** [November 24, 2011, 5:17pm UTC](https://discuss.elastic.co/t/problem-with-preloaded-scripts-file-size/5967/1 "2011-11-24T17:17:49Z")

</div>

Hello,  
I have a problem with my Preloaded Scripts. If the file is too big ES  
doesn't find the file.

For my test the document format is:  
{"\_index":"test","\_type":"res","\_id":"1","\_version":1,"exists":true,  
"\_source" : {"test":"1","liste":["a1","a2","a3"]}}

My query:  
$data = array('query'=\> array('terms'=\> array('test'=\> array('1'))),  
'script\_fields'=\> array('test1'=\>array('script'=\>'test')));

And my preloaded scripts, file test.js:

Tab = doc["liste"].values;  
test = new Array;  
test["a5"] = 274;  
test["a4"] = 388;  
test["a3"] = 454;  
test["a2"] = 339;  
test["a1"] = 21;

count = 0;  
for (Val in Tab){  
if(test[Tab[Val]]==undefined){  
add = 1000000;  
}  
else{  
add = test[Tab[Val]];  
}

```
count = count + add ;

```

}  
count;

If in my preloaded script I have just 1 000 values in the array, there  
is no problem.  
But if I have more than 10 000 values in the array, I get this error  
message  
{"took":12,"timed\_out":false,"\_shards":{"total":5,"successful":  
4,"failed":1,"failures":[{"status":  
500,"reason":"EcmaError[ReferenceError: "test" n'est pas dÃ©fini  
(Script7.js#1)]"}]},"hits":{"total":1,"max\_score":9.24269,"hits":[]}}

What can I do? Because I would like to make some test with more than 1  
000 000 values in the array, if it's possible thanks.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 24, 2011, 6:40pm UTC](https://discuss.elastic.co/t/problem-with-preloaded-scripts-file-size/5967/2 "2011-11-24T18:40:16Z")

</div>

A recreation would help, gist the script that fails, and gist curl  
recreation and steps. See more at [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help). A note  
though, initializing an array with 10k values in the script is problematic,  
since the script is evaluated fo reach search request (though compiled  
once). Maybe the addition of "reference data" script, that is run once and  
shared between different execution of the script makes sense in this case,  
but that can come later.

On Thu, Nov 24, 2011 at 7:17 PM, alsab [alex1.sab@laposte.net](mailto:alex1.sab@laposte.net) wrote:

> Hello,  
> I have a problem with my Preloaded Scripts. If the file is too big ES  
> doesn't find the file.
> 
> For my test the document format is:  
> {"\_index":"test","\_type":"res","\_id":"1","\_version":1,"exists":true,  
> "\_source" : {"test":"1","liste":["a1","a2","a3"]}}
> 
> My query:  
> $data = array('query'=\> array('terms'=\> array('test'=\> array('1'))),  
> 'script\_fields'=\> array('test1'=\>array('script'=\>'test')));
> 
> And my preloaded scripts, file test.js:
> 
> Tab = doc["liste"].values;  
> test = new Array;  
> test["a5"] = 274;  
> test["a4"] = 388;  
> test["a3"] = 454;  
> test["a2"] = 339;  
> test["a1"] = 21;
> 
> count = 0;  
> for (Val in Tab){  
> if(test[Tab[Val]]==undefined){  
> add = 1000000;  
> }  
> else{  
> add = test[Tab[Val]];  
> }
> 
> count = count + add ;  
> }  
> count;
> 
> If in my preloaded script I have just 1 000 values in the array, there  
> is no problem.  
> But if I have more than 10 000 values in the array, I get this error  
> message  
> {"took":12,"timed\_out":false,"\_shards":{"total":5,"successful":  
> 4,"failed":1,"failures":[{"status":  
> 500,"reason":"EcmaError[ReferenceError: "test" n'est pas dÃ©fini  
> (Script7.js#1)]"}]},"hits":{"total":1,"max\_score":9.24269,"hits":}}
> 
> What can I do? Because I would like to make some test with more than 1  
> 000 000 values in the array, if it's possible thanks.

---

<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, 3:47am UTC](https://discuss.elastic.co/t/problem-with-preloaded-scripts-file-size/5967/3 "2017-07-06T03:47:32Z")

</div>


