Most efficient way to search an array for a value (Painless)

I wrote a script for generating a calculated field. It's written in Painless. I'm adding a feature to it where I need to see if an array that is on the document has a value in it. The property in the document is called colors and the data looks a bit like this:

[
  { id: 1, name: 'red' },
  { id: 2, name: 'green' },
  { id: 3, name: 'blue'}
]

There actually a ton of values in there. My search query has a parameter called colors that looks like this:

omit_colors: [1, 3]

What I want to do is write a bit of code that will iterate through the colors property on the doc and see if any values in the omit_colors property is in there. Right now, I have it written as a nested loop that iterates over colors and checks each against each value in omit_colors. It works, but feels a little messy. Can anyone recommend the most efficient way to do this?

BTW, the nature of our query and results are such that we can't just set up a filter in the query.

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