'must' Clause

The 'must' clause specifies conditions that must be satisfied for a document to be considered a match. In terms of logical operators, it corresponds to 'and' operator.

must' Clause Score

Under the 'must' clause, each element is assigned a probabilistic rarity score, and the total score for the 'must' clause is calculated by combining these individual scores. Unless specified otherwise, the score is based on the TF-IDF scoring model. .The 'must' clause is used when you want all specified conditions to be satisfied for a document to be considered a match. Since each score represent a different probability, the combined score is a product of the individual scores

Score = score1 * score2 * score3...

Note: This scoring method assumes the 'must' clause are independent of one another

Example -

{
  "query": {
    "bool": {
      "must": [
        { "term": { "Bird": "Asian Koel" } },
        { "range": { "price": { "gte": 10} } },
        { "term": { "In Stock": "true" } }
      ]
    }
  }
}

In the above example, all candidates must satisfy all three conditions -

  • exact match over the 'bird' field, with score equals TF-IDF score for { "Bird": "Asian Koel" }

  • The 'price' field must be greater than or equal to 10

  • match over "In Stock" field, with score equals TF-IDF score for { "In Stock": "true" }

The overall score will be a product of the individual scores.

Last updated