Multiple MUST inside SHOULD query on Elasticsearch 6.6

36 views Asked by At

I am trying to build a search filter/query to return either one of the two conditions.

(first_score >= 5 AND first_score <= 18) AND (last_score <= 20)

OR

(first_score = 19) AND (last_score = 0)

Sample document:

first_score = 18
last_score = 1

I've tried the following Elasticsearch filter, but I am not getting the correct result. Looks like the "OR" condition isn't working?

Chewy::JobsIndex.filter(
  bool: {
    should: [
      bool: {
        must: [
          range: { first_score: { gte: 5, lte: 18 } },
          range: { last_score: { lte: 20 } }
        ]
      },
      bool: {
        must: [
          term: { first_score: 19 },
          term: { last_score: 0 }
        ]
      }
    ]
  }      
)
0

There are 0 answers