1

I have dsl query which need to return

  • Country Owner is list of dictionaries
  • Territory Owner is list of dictionaries
  • Need to check where id is part of that dictionary
  • My query which is below which return which is 'and' but i need OR operation
a = {'from': 0, 'size': 200,'query': {
    'bool': {
      'must': [
        {
          'terms': {
            'Country Owner.id.keyword': [
              'ABC101'
            ]
          }
        },
        {
          'terms': {
            'Territory Owner.id.keyword': [
              'ABC101'
            ]
          }
        }
      ]
    }
  }
}
sim
  • 524
  • 3
  • 14

1 Answers1

1

Simply change must by should and you're good to go

a = {'from': 0, 'size': 200,'query': {
    'bool': {
      'minimum_should_match': 1,                <--- change this
      'should': [                               <--- change this
        {
          'terms': {
            'Country Owner.id.keyword': [
              'ABC101'
            ]
          }
        },
        {
          'terms': {
            'Territory Owner.id.keyword': [
              'ABC101'
            ]
          }
        }
      ]
    }
  }
}
Val
  • 207,596
  • 13
  • 358
  • 360
  • why minimum_should_match, is that required? – sim Aug 23 '21 at 12:48
  • 1
    It's only necessary if you're going to add filter or must clauses along the way, but if you have only should, you can ditch it... even though it doesn't hurt leaving it – Val Aug 23 '21 at 12:56