Difference between score of 0 and score of 1 for filtered queries (using bool query with filter vs constant_score query with filter)

Hello,

Is there a difference between a score of 0 and a score of 1 in a filtered query. I am trying to decide which query to use. I would like to submit the queries under the filter context as it should be more performant (use of cache) and I don't need scoring. I am using ES 6.2. Which of the 2 options would perform better?

Score of 0:

{
  "query": {
    "bool": {
      "filter": {
        "bool": {
          "must": {
            "term": {
              "status": "active"
            }
          }
        }
      }
    }
  }
}

Score of 1:

{
  "query": {
    "constant_score": {
      "filter": {
        "bool": {
          "must": {
            "term": {
               "status": "active"
            }
          }
        }
      }
    }
  }
}

Thanks!

If there are no other parts of the query, it doesn't matter at all. Scores are just relative, and if all docs have the same value (zero or one) it's the same.

If your query has other scoring components, it depends if you want the filtered values to impact the score at all. If you don't want them to impact the score, just filter values, the filter clause of a bool is what you want since it gives zero score to those docs.

If you want the act of filtering docs to influence the score, constant_score is what you want since it can impart an arbitrary boost. The default is 1, but you can change that with the boost param

Great! Just what I was looking for. Thanks!

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