| must | 必须匹配,参与评分 |
|---|---|
| filter | 必须匹配,不评分,可缓存 |
| should | 应匹配:无 must/filter 时至少命中一个,可用 minimum_should_match 调整 |
| must_not | 必须不匹配,不评分 |
示例
示例
GET /my-index/_search
{
"query": {
"bool": {
"must": [ { "match": { "title": "search" } } ],
"filter": [
{ "term": { "status": "published" } },
{ "range": { "publish_date": { "gte": "2024-01-01" } } }
],
"must_not": [ { "term": { "flag": "spam" } } ],
"should": [ { "term": { "tags": "featured" } } ],
"minimum_should_match": 0
}
}
}bool 子句顺序不影响执行计划,但把过滤条件放 filter 能显著减少评分计算量。