题记
Multi-match query 的目的多字段匹配,但 Multi-match query 中的 best_fields, most_fields, cross_fields 分不清楚,都什么含义?
下面我们一一举例解读。
best_fields
为默认值,如果不指定,默认best_fields 匹配。
含义:多个字段中,返回评分最高的。 类似:dis_max query。 等价举例:(两个一起看,加深理解)
默认 best_fields 与 dis_max等价
POST blogs/_search
{
"query": {
"multi_match": {
"type": "best_fields",
"query": "Quick pets",
"fields": [
"title",
"body"
],
"tie_breaker": 0.2
}
}
}复制
与上述best_fields等价
POST blogs/_search
{
"query": {
"dis_max": {
"queries": [
{
"match": {
"title": "Quick pets"
}
},
{
"match": {
"body": "Quick pets"
}
}
],
"tie_breaker": 0.2
}
}
}复制
most_fields
含义:匹配多个字段,返回的综合评分(非最高分)
类似:bool + 多字段匹配。
等价举例:(两个一起看,加深理解)
most_fields 与下面的 bool 查询等价。
GET /titles/_search
{
"query": {
"multi_match": {
"query": "barking dogs",
"type": "most_fields",
"fields": [
"title^10",
"title.std"
]
}
}
}复制
与上面的most_fields等价
GET titles/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": {
"query": "barking dogs",
"boost": 10
}
}
},
{
"match": {
"title.std": "barking dogs"
}
}
]
}
}
}复制
cross_fields
含义:跨字段匹配——待查询内容在多个字段中都显示。 类似:bool + dis_max 组合。 等价举例:(两个一起看,加深理解)
与下面的bool查询逻辑一致
GET test003/_validate/query?explain=true
{
"query": {
"multi_match": {
"query": "Will Smith",
"type": "cross_fields",
"fields": [
"first_name",
"last_name"
],
"operator": "and"
}
}
}
GET test003/_validate/query?explain=true复制
返回:
"explanation" : "+blended(terms:[first_name:will, last_name:will]) +blended(terms:[first_name:smith, last_name:smith])"
复制
与上面的cross_fields 基本等价,评分不一致,待深究
POST test003/_validate/query?explain=true
{
"query": {
"bool": {
"must": [
{
"dis_max": {
"queries": [
{
"match": {
"first_name": "Will"
}
},
{
"match": {
"last_name": "Will"
}
}
]
}
},
{
"dis_max": {
"queries": [
{
"match": {
"first_name": "Smith"
}
},
{
"match": {
"last_name": "Smith"
}
}
]
}
}
]
}
}
}复制
小结
类似辨识度不好区分的 Elastic 知识点,考虑通过实战例子加以区分,实战一把,有助于提升选型效率。
参考:
1、https://zhuanlan.zhihu.com/p/24832190
2、https://github.com/mingyitianxia/deep_elasticsearch
:elastic6(仅有少量坑位了),和 BAT 大佬一起精进 Elastic 技术!
推荐阅读:

更短时间更快习得更多干货!
文章转载自铭毅天下Elasticsearch,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
数据库国产化替代深化:DBA的机遇与挑战
代晓磊
1338次阅读
2025-04-27 16:53:22
2025年4月国产数据库中标情况一览:4个千万元级项目,GaussDB与OceanBase大放异彩!
通讯员
824次阅读
2025-04-30 15:24:06
【活动】分享你的压箱底干货文档,三篇解锁进阶奖励!
墨天轮编辑部
545次阅读
2025-04-17 17:02:24
一页概览:Oracle GoldenGate
甲骨文云技术
512次阅读
2025-04-30 12:17:56
GoldenDB数据库v7.2焕新发布,助力全行业数据库平滑替代
GoldenDB分布式数据库
486次阅读
2025-04-30 12:17:50
阿里云 Elasticsearch Serverless 检索增强型 8.17 版来袭!
阿里云大数据AI技术
381次阅读
2025-04-18 10:24:15
优炫数据库成功入围新疆维吾尔自治区行政事业单位数据库2025年框架协议采购!
优炫软件
370次阅读
2025-04-18 10:01:22
给准备学习国产数据库的朋友几点建议
白鳝的洞穴
364次阅读
2025-05-07 10:06:14
XCOPS广州站:从开源自研之争到AI驱动的下一代数据库架构探索
韩锋频道
320次阅读
2025-04-29 10:35:54
MySQL 30 周年庆!MySQL 8.4 认证免费考!这次是认真的。。。
数据库运维之道
309次阅读
2025-04-28 11:01:25