Most efficient way to do a lookup (<100 items) in a painless script


(Thomas Wozniakowski) #1

Hi,

I need to do some aggregations on a scripted term. The term will be calculated from a keyword field stored in my index.

The script will need to:

  1. Grab the first substring before a whitespace character
  2. Check it against a list/map of values and see if it matches any of them
  3. If it matches, rewrite the term to a new mapped value, otherwise keep the original

I'm wondering what the most efficient way to handle step 2 would be in a painless script. My initial thought was using a Map<String,String>, but then I thought this might mean the map is discarded and created for every single document that gets passed through the script. Would it be more efficient to do a really big if-else stack? As much as I dislike this idea, performance will be important here, and this has to be done via script because the mappings might change over time.

Would really appreciate any insight on this - thanks for your help!

Tom


(Christian Dahlqvist) #2

If performance is important, the more processing you can do before indexing the document, the bettet.


(Thomas Wozniakowski) #3

Oh, for sure, but given I can't pre-process here as the list/map will change (and the output must change retroactively), this has to happen in realtime.