A must clause is a Boolean query clause that requires documents to match its inner queries. A positive match contributes to relevance scoring. section 2.5.2 section 2.5.1
Find TVs priced from $700 to $800
GET products/_search { "query": { "bool": { "must": [ { "match": { "product": "TV" } }, { "range": { "price": { "gte": 700, "lte": 800 } } } ] } } } Both leaf queries must match: the product must be a TV and its price must fall within the range. section 11.3.3
Use the clause to build increasingly specific search criteria:
- Place one leaf query inside must for a focused requirement, such as matching books authored by Joshua Bloch. section 2.5.2
- Add multiple queries as array entries to express AND logic across full-text, term-level, and range criteria. section 11.3.3 section 11.3
- Combine must with must_not, should, and filter when requirements include exclusions, preferences, or non-scoring constraints. section 11.3.8
Listing 11.3 Finding TVs within a price range
GET products/_search
{
"query": {
"bool": {
"must": [ #1
{
"match": { #2
"product": "TV"
}
},
{
"range": { #3
"price": {
"gte": 700,
"lte": 800
}
}
}
]
}
}
}
Shows a runnable Elasticsearch request combining product matching with an inclusive numeric price range. section 11.3.3
