Getting a no_viable_alt_exception only when trying to filter using a scripted field

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

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.