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
