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

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

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

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.

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