You need to add an else branch to your scripted field, otherwise the lambda used for embedding scripted fields in filters fails for the cases when the field does not exist.
Also, keep in mind that you have to recreate the filter, as that's static so it won't update by itself if you update the scripted field.
There's a difference on how scripted fields work in Discovery (those are computed in Kibana) and those that used in filters (the code is wrapped in a boolean compare and it's sent as part of the query to ES and computed there).
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.