
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等價
"dis_max": {
"queries": [
{
"match": {
"title": "Quick pets"
}
},
"body": "Quick pets"
}
most_fields
含義:比對多個字段,傳回的綜合評分(非最高分)
類似:bool + 多字段比對。
most_fields 與下面的 bool 查詢等價。
GET /titles/_search
"query": "barking dogs",
"type": "most_fields",
"title^10",
"title.std"
]
與上面的most_fields等價
GET titles/_search
"bool": {
"should": [
"title": {
"query": "barking dogs",
"boost": 10
}
"title.std": "barking dogs"
cross_fields
含義:跨字段比對——待查詢内容在多個字段中都顯示。
類似:bool + dis_max 組合。
與下面的bool查詢邏輯一緻
GET test003/_validate/query?explain=true
"query": "Will Smith",
"type": "cross_fields",
"first_name",
"last_name"
"operator": "and"
傳回:
"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
"must": [
"dis_max": {
"queries": [
{
"match": {
"first_name": "Will"
}
},
"last_name": "Will"
}
]
"first_name": "Smith"
"last_name": "Smith"
小結
類似辨識度不好區分的 Elastic 知識點,考慮通過實戰例子加以區分,實戰一把,有助于提升選型效率。
參考:
1、
https://zhuanlan.zhihu.com/p/248321902、
https://github.com/mingyitianxia/deep_elasticsearch加微信:elastic6(僅有少量坑位了),和 BAT 大佬一起精進 Elastic 技術!