| constant_score | 子查询不评分、统一给 boost 值,等价高分过滤 |
|---|---|
| boosting | positive 命中加分、negative 命中降权,negative_boost 控制降幅 |
| 适用 | 排序需固定权重、或想让某类文档排后但不排除 |
示例
示例
GET /my-index/_search
{
"query": {
"constant_score": {
"filter": { "term": { "user.id": "kimchy" } },
"boost": 1.2
}
}
}
GET /my-index/_search
{
"query": {
"boosting": {
"positive": { "match": { "title": "elastic" } },
"negative": { "term": { "tier": "archived" } },
"negative_boost": 0.2
}
}
}纯过滤场景优先用 bool.filter,它不评分且匹配结果可缓存;constant_score 适合需要固定 boost 的场合。