Script filter field value is in array

Here is a part of my query:

 must_not: {
    script: {
      script: {
        source: "doc['type.keyword'].value=='CHANNEL' ? doc['id'].value == 0 : ['1','3','7'].contains(doc['id'].value"),
        lang: 'painless'
      }
    }
  }

How can I check if doc['id'].value has a value from an array?

What type is your id field (in your mappings)?

integer type

I've tried different ways:

    source:"doc['type.keyword'].value=='CHANNEL' ? doc['id'].value == 0 : params.ids.values.contains(doc['id'].value)",
     params: {
       ids: [5,6]
    } - NO ERROR. JUST NOT FILTERING

    source:"doc['type.keyword'].value=='CHANNEL' ? doc['id'].value == 0 : params.ids.contains(doc['id'].value)",
     params: {
       ids: ['5','6']
    } - NO ERROR. JUST NOT FILTERING

    source:"doc['type.keyword'].value=='CHANNEL' ? doc['id'].value == 0 : for (el in params.ids) {doc['id'].value==el}",
     params: {
       ids: ['5','6']
    } . ERROR

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