Elasticsearch 常用查询类型?
发布于
一、全文查询
- match:对查询词分词后匹配。
- match_phrase:短语匹配,词序固定。
- multi_match:多字段匹配。
- query_string:支持 Lucene 查询语法。
二、精确查询
- term:精确匹配不分词的值。
- terms:多值精确匹配。
- range:范围查询。
- exists:字段存在。
三、复合查询
- bool:组合 must/should/must_not/filter。
- filter:过滤,不评分,可缓存。
- constant_score:固定评分。
四、示例
{
"query": {
"bool": {
"must": [{ "match": { "title": "Java" } }],
"filter": [{ "range": { "price": { "gte": 100 } } }]
}
}
}
五、注意
- 过滤用 filter,不参与评分,性能好。
- 避免深度分页(用 scroll 或 search_after)。