liveBook · Manning

Minimum match threshold

As explained in Elasticsearch in Action, Second Edition

The minimum_should_match setting specifies the minimum number of optional query clauses or terms that must match for a document to qualify.

Minimum match threshold controls how many optional terms or clauses must match before Elasticsearch accepts a document. For “Java Complete Guide,” setting it to 2 requires any two of the three terms. section 10.5.5

Listing 10.8 Matching at least two words
GET books/_search
{
  "query": {
    "match": {
      "title": {
        "query": "Java Complete Guide",
        "operator": "OR",
        "minimum_should_match": 2   #1
      }
    }
  }
}

Require at least two terms from a three-term book-title query while retaining OR-style matching for the remaining terms. section 10.5.5

Use the setting to control optional matching precisely:

  • Set it to 2 to require at least two matching terms or clauses. section 10.5.5
  • Set it to the total number of terms to make matching equivalent to AND. section 10.5.5
  • Set it to 1 in a bool query when at least one should clause must match. section 11.3.6
  • Remember that should clauses are optional beside must clauses unless minimum_should_match changes that requirement. section 11.3.6
Listing 11.11 Using the minimum_should_match parameter
GET products/_search
{ 
  "_source": ["product","brand","overview", "price","colour"], 
  "query": {
    "bool": {
      "must": [{
          "match": {
            "product": "TV"
          }
        },
        {
          "match": {
            "brand": "LG"
          }
        }], 
      "should": [{
          "range": {
            "price": {
              "gte": 500,
              "lte": 2000
            }
          }
        },
        {
          "match": {
            "colour": "silver"
          }
        },
        {
          "match_phrase_prefix": {
            "overview": "4K Ultra HD"
          }
        }],
      "minimum_should_match": 1    #1
    }
  }
}

Require an LG television to satisfy at least one of three optional conditions: price range, silver colour, or 4K Ultra HD overview. section 11.3.6

A matching should clause can also boost relevance. Without a minimum requirement, optional matches affect the score; with a requirement, documents must satisfy the selected number of optional criteria to qualify. section 11.3.6

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Defines term-level and bool-query behavior with examples, defaults, scoring effects, and an AND equivalence.
Examples
Uses a three-term book-title query and a television query combining price, colour, and 4K Ultra HD criteria.
What it assumes
Assumes familiarity with query terms and clauses while demonstrating match, bool, must, should, range, and phrase-prefix queries.
What you can do after
Configure Elasticsearch queries that require selected numbers of optional terms or clauses while controlling relevance boosts.
How it connects
Connects full-text search, match queries, bool queries, must clauses, should clauses, AND, OR, relevance scoring, and range queries.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elasticsearch in Action, Second Edition. The section links point to the parts of the book it draws on.