MLT query to change score only


(Eugene Prokopiev) #1

Hi,

Is it possible to write MLT query to ES which will not filter results, but will change score only, so unmatched documents will be at the end of result set?


(Eugene Prokopiev) #2

I tried to do this with simple term query first:

POST locations/_search?size=100
{
  "query": {
    "bool": {
      "should": {
        "term": {
          "country_code" : "mz"
        }
      },
      "minimum_should_match": 0
    }
  }
}

I used "should" and "minimum_should_match" due to description from https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html:

In a boolean query with no must or filter clauses, one or more should clauses must match a document. The minimum number of should clauses to match can be set using the minimum_should_match parameter.

So, I guessed to see documents with "country_code" : "mz" and all other documents next, but I see only 18 documents with "country_code" : "mz" and not 100 documents as described by size=100.

Where is my error and how to apply any query to score only without filtering?


(Eugene Prokopiev) #3

Looks like "minimum_should_match" can't be less than 1, but I can add "match_all":

POST locations/_search?size=100
{
  "query": {
    "bool": {
      "should": [
        {
          "match_all": {}
        },
        {
          "term": {
            "country_code": "mg"
          }
        }
      ],
      "minimum_should_match": 1
    }
  }
}

(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.