We want to implement filters using painless scripts that work by checking if a string is a member of some potentially large set (hundreds or thousands of members) determined ahead of time. E.g., suppose the set contains a statically determined whitelist or blacklist. Set membership should be fast once the set has been built, which is why we would like to preserve it between painless method calls.
I cannot find any way to do this. Of course, I can construct a new copy of the set (or a list) each time the painless script is called, but this amounts to doing linear search. Is there any kind of initialization that can be done once (essentially at class-loading time in the JVM) so that it does not need to be repeated for each call?
I realize that painless is somewhat limited and that I could look into writing custom Java scripts. I would like to avoid that for now. This seems like an application that other users would want. Am I missing something obvious?