# Getting a no\_viable\_alt\_exception only when trying to filter using a scripted field

**URL:** <https://discuss.elastic.co/t/getting-a-no-viable-alt-exception-only-when-trying-to-filter-using-a-scripted-field/183145>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [May 28, 2019, 4:23pm UTC](https://discuss.elastic.co/t/getting-a-no-viable-alt-exception-only-when-trying-to-filter-using-a-scripted-field/183145 "2019-05-28T16:23:47Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Larry\_Gregory](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/larry_gregory/32/34969_2.png) [@Larry\_Gregory](https://discuss.elastic.co/u/Larry_Gregory)\
**Post date:** [May 28, 2019, 9:17pm UTC](https://discuss.elastic.co/t/getting-a-no-viable-alt-exception-only-when-trying-to-filter-using-a-scripted-field/183145/4 "2019-05-28T21:17:14Z")

</div>

Thanks for the mapping. I have good news and bad news. The good news is that I was able to reproduce the error you're seeing.

The bad news is that it's related to how Kibana has to wrap the painless script in order to execute it in the context of a filter. It places your script into a lambda in order to run it: [https://github.com/elastic/kibana/blob/01c862762263541a006f539f5a26ffdd4881b103/packages/kbn-es-query/src/filters/phrase.js#L81:L84](https://github.com/elastic/kibana/blob/01c862762263541a006f539f5a26ffdd4881b103/packages/kbn-es-query/src/filters/phrase.js#L81:L84)

Based on that, I'm thinking that you can't declare inline functions such as `getMonth`, `cleanString`, etc within a lamdba. I'm not sure where to go from here, as I'm sure you don't want to inline that logic every place you're using it in the script. I'll see if any Painless experts are around who might be able to help a bit more.

---

_[View the full topic](https://discuss.elastic.co/t/getting-a-no-viable-alt-exception-only-when-trying-to-filter-using-a-scripted-field/183145)._
