sim
sim

Reputation: 488

How to put not condition on particular id's not to search in DSL query

This is the dictionary pattern of elasticsearch {'id': 3},{'id': 4},{'id': 5},{'id': 6}

Below is the query to search 'Country Owner.id.keyword' and 'Territory Owner.id.keyword'

a = {'from': 0, 'size': 200,'query': {
    'bool': {
      'should': [                              
        {
          'terms': {
            'Country Owner.id.keyword': [
              'ABC101'
            ]
          }
        },
        {
          'terms': {
            'Territory Owner.id.keyword': [
              'ABC101'
            ]
          }
        }
      ]
    }
  }
}

Upvotes: 0

Views: 145

Answers (1)

Bhavya
Bhavya

Reputation: 16172

You can use a terms query inside a must_not clause

{
  "query": {
    "bool": {
      "should": [
        {
          "terms": {
            "Country Owner.id.keyword": [
              "ABC101"
            ]
          }
        },
        {
          "terms": {
            "Territory Owner.id.keyword": [
              "ABC101"
            ]
          }
        }
      ],
      "must_not": {
        "terms": {
          "id": [
            3,
            4,
            5
          ]
        }
      }
    }
  }
}

Upvotes: 1

Related Questions