Find string in array

I have an array that contains some bucket keys. i want to do something for each bucket if their key is in my array.
here is my code so far:

"script": {
      "source": """
            def docs = [];
            def -> p.key).collect(Collectors.toList());
            def -> p.key).collect(Collectors.toList());
            def hits = ctx.payload.aggregations.event_types.buckets.add.users.buckets;
            def user = -> u.key).filter(u -> removes.contains(u)).filter(u -> logins.contains(u)).toArray();
            for (hit in hits){
              if (user.values.contains(hit.key)){
              def document = [
                   ///DO SOMETHING..
            return ['_doc':docs];
      "lang": "painless"

But I just can't figure out how to check the condition for that ( check if bucket keys exist in user array)

There is a Debug.explain() feature in painless, that allows you to check the state of an expression. Running this before the if might help to figure out the values of user.values and hit.key...


Thanks Alex, i'll check it out.
For now I used a nested loop that compare current key value with every key in the user array and it's working fine.

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