0

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 }
        ]
      }
    ]
  }      
)
chuki
  • 1
  • Does this answer your question? [elasticsearch bool query combine must with OR](https://stackoverflow.com/questions/28538760/elasticsearch-bool-query-combine-must-with-or) – Paulo Nov 07 '22 at 10:45
  • What does `filter` do? If it just makes a query, this should work. What extra results are you getting – Tushar Shahi Nov 07 '22 at 10:58

0 Answers0