# Need help with painless scripting

**URL:** <https://discuss.elastic.co/t/need-help-with-painless-scripting/130059>\
**Category:** Elasticsearch\
**Created:** [April 30, 2018, 7:18pm UTC](https://discuss.elastic.co/t/need-help-with-painless-scripting/130059 "2018-04-30T19:18:30Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [May 1, 2018, 5:15pm UTC](https://discuss.elastic.co/t/need-help-with-painless-scripting/130059/3 "2018-05-01T17:15:49Z")

</div>

In your script you have 2 lists. e and c. The error is that you are referencing a list item that is not there. You need to test if the lists are filled before you de-reference them.

This might help:

- [Painless link 1](https://discuss.elastic.co/t/painless-if-doc-field-value-in-list/126598)
- [main docs.](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/modules-scripting-painless-syntax.html)
- [This a good howto](https://www.compose.com/articles/how-to-script-painless-ly-in-elasticsearch/)

---

_[View the full topic](https://discuss.elastic.co/t/need-help-with-painless-scripting/130059)._
