摘要
返回一個會多個查詢子句匹配的文檔。如果返回的文檔與多個查詢子句匹配,則dis_max查詢會爲該文檔分配來自所有查詢子句的最高相關性得分,再加上其他得分的和與tie_breaker
的積。
換句話說,您可以使用dis_max搜索來降低最佳匹配子句在相關性得分計算中所佔的比重。
請求參數
queries
,必選項。包含一個或多個查詢子句。返回的文檔,必須匹配其中的一個或多個子句。如果一個文檔匹配多個查詢子句,Elasticsearch 將會使用最高的相關性得分。tie_breaker
,選填項。介於0,1.0
之間的浮點數。默認爲0.0
,用於增加,除最佳匹配子句外的其他匹配子句的佔總相關性得分的比重。如果一個文檔匹配多個子句,dis_max查詢將計算該文檔的相關性得分,如下所示:- 從具有最高分數的匹配子句中獲取相關性分數。
- 將任何其他匹配子句的分數乘以該
tie_breaker
值。 - 將最高分數加到相乘的分數上。
請求示例
可以仔細對比兩次請求,得分結果的差異
/* 第一種:有tie_breaker參數 */
GET blak_new/_search
{
"query": {
"dis_max" : {
"queries" : [
{ "term" : { "state" : "VA" }},
{ "term" : { "state" : "TN" }},
{"terms": {
"state": [
"VA",
"TN"
]
}}
],
"tie_breaker" : 0.7
}
}
}
/* 第二種:無tie_breaker參數 */
GET blak_new/_search
{
"query": {
"dis_max" : {
"queries" : [
{ "term" : { "state" : "VA" }},
{ "term" : { "state" : "TN" }},
{"terms": {
"state": [
"VA",
"TN"
]
}}
]
}
},
"from":10
}
請求結果
/* 第一種:有tie_breaker參數 */
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 43,
"relation" : "eq"
},
"max_score" : 7.2276816,
"hits" : [
{
"_index" : "blak_new",
"_type" : "_doc",
"_id" : "1011",
"_score" : 7.2276816,
"_source" : {
"account_number" : 164,
"balance" : 9101,
"firstname" : "Cummings",
"lastname" : "Holt",
"age" : 26,
"gender" : "F",
"employer" : "Comtrak",
"email" : "[email protected]",
"city" : "Chaparrito",
"state" : [
"VA",
"TN"
],
"state_number" : 2
}
},
{
"_index" : "blak_new",
"_type" : "_doc",
"_id" : "13",
"_score" : 4.7031746,
"_source" : {
"account_number" : 13,
"balance" : 32838,
"firstname" : "Nanette",
"lastname" : "Bates",
"age" : 28,
"gender" : "F",
"address" : "789 Madison Street",
"employer" : "Quility",
"email" : "[email protected]",
"city" : "Nogal",
"state" : "VA"
}
}
]
}
}
/* 第二種:無tie_breaker參數 */
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 43,
"relation" : "eq"
},
"max_score" : 4.003175,
"hits" : [
{
"_index" : "blak_new",
"_type" : "_doc",
"_id" : "988",
"_score" : 4.003175,
"_source" : {
"account_number" : 988,
"balance" : 17803,
"firstname" : "Lucy",
"lastname" : "Castro",
"age" : 34,
"gender" : "F",
"address" : "425 Fleet Walk",
"employer" : "Geekfarm",
"email" : "[email protected]",
"city" : "Mulino",
"state" : "VA"
}
},
{
"_index" : "blak_new",
"_type" : "_doc",
"_id" : "1011",
"_score" : 4.003175,
"_source" : {
"account_number" : 164,
"balance" : 9101,
"firstname" : "Cummings",
"lastname" : "Holt",
"age" : 26,
"gender" : "F",
"employer" : "Comtrak",
"email" : "[email protected]",
"city" : "Chaparrito",
"state" : [
"VA",
"TN"
],
"state_number" : 2
}
}
]
}
}