0

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'

  • I need to put one condition saying it should not search with id: [3,4,5] so my output will contain only from 6 with value 'ABC101' if present
a = {'from': 0, 'size': 200,'query': {
    'bool': {
      'should': [                              
        {
          'terms': {
            'Country Owner.id.keyword': [
              'ABC101'
            ]
          }
        },
        {
          'terms': {
            'Territory Owner.id.keyword': [
              'ABC101'
            ]
          }
        }
      ]
    }
  }
}
sim
  • 524
  • 3
  • 14

1 Answers1

1

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
          ]
        }
      }
    }
  }
}
ESCoder
  • 15,431
  • 2
  • 19
  • 42
  • can you answer https://stackoverflow.com/questions/72656359/remove-stopwords-or-exclusion-list-while-retrieving-data-from-elasticsearch – sim Jun 17 '22 at 08:35