Any way to initialize a large set once in painless script for repeat use?

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?

maybe this resp can slove your problem:flashtext

I don't see how this would help, since it's written in python. Am I missing something? I am looking for a solution that runs as a painless script in the elasticsearch JVM.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.