Search code examples
elasticsearchelasticsearch-5elasticsearch-7

After upgrading to Elasticsearch v7, queries return all results


I am trying to upgrade my cluster Elasticsearch v7, my queries seem to return a lot of results, even for impossible requests

Previously, when searching "qdsssq", my search engine would find nothing. After upgrading to v7, a similar query returns almost results. Even when I remove all should clauses of my query, I'm getting a lot of results. However, it seems the scoring still works, and I type plausible queries, I am indeed getting most relevant results first (but even non-matching results as well). Can you help me figure out the problem ?

Here is an example of query I was firing on elasticsearch v5 that was producing results as expected (and that seem to end up returning the whole DB now on ESv7). I have only included a single should for FR/EN for simplicity

{
  index: "profiles",
  type: nil,
  body: {
    query: {
      function_score: {
        query: {
          bool: {
            disable_coord: true,
            filter: {
              bool: {
                filter: [{
                  term: {
                    indexable: true
                  }
                }],
                should: [{
                  match_phrase: {
                    : "description.french" => {
                      query: "qdsssq",
                      boost: 1,
                      slop: 50,
                      analyzer: "french_heavy"
                    }
                  }
                }, {
                  match_phrase: {
                    : "description.english" => {
                      query: "qdsssq",
                      boost: 1,
                      slop: 50,
                      analyzer: "english"
                    }
                  }
                }]
              }
            },
            should: [{
              match_phrase: {
                : "description.french" => {
                  query: "qdsssq",
                  boost: 1,
                  slop: 50,
                  analyzer: "french_heavy"
                }
              }
            }, {
              match_phrase: {
                : "description.english" => {
                  query: "qdsssq",
                  boost: 1,
                  slop: 50,
                  analyzer: "english"
                }
              }
            }]
          }
        },
        functions: [],
        score_mode:: sum,
        boost_mode:: multiply
      }
    }
  },
  size: 12,
  from: 0
}

Did I miss some breaking change that would explain this ? Is the removal of the filter context (not really sure what that means) related ? How can I fix my query so results that do not match at all are not included in the results ?

I am using - Elasticsearch v7.1 on AWS - the Ruby gem elasticsearch-7.3.0


Solution

  • Yes, it is related to the removal of filter context you were referring to.

    Please try to set minimum_should_match: 1 in both bool queries.

    You might also find this answer helpful.