ElasticSearch BM-25
https://www.cnblogs.com/novwind/p/15177871.html
通过kibana中配置explain属性后,可以看出来每个文档的得分由:
score = boost * idf *tf
组成。
"_explanation" : {
"value" : 1.3767608,
"description" : "sum of:",
"details" : [
{
"value" : 1.0121177,
"description" : "max of:",
"details" : [
{
"value" : 1.0121177,
"description" : "weight(title:student in 0) [PerFieldSimilarity], result of:",
"details" : [
{
"value" : 1.0121177,
"description" : "score(freq=1.0), computed as boost * idf * tf from:",
"details" : [
{
"value" : 3.3000002,
"description" : "boost",
"details" : [ ]
},
{
"value" : 0.6931472,
"description" : "idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:",
"details" : [
{
"value" : 2,
"description" : "n, number of documents containing term",
"details" : [ ]
},
{
"value" : 4,
"description" : "N, total number of documents with field",
"details" : [ ]
}
]
},
{
"value" : 0.44247788,
"description" : "tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:",
"details" : [
{
"value" : 1.0,
"description" : "freq, occurrences of term within document",
"details" : [ ]
},
{
"value" : 1.2,
"description" : "k1, term saturation parameter",
"details" : [ ]
},
{
"value" : 0.75,
"description" : "b, length normalization parameter",
"details" : [ ]
},
{
"value" : 4.0,
"description" : "dl, length of field",
"details" : [ ]
},
{
"value" : 3.75,
"description" : "avgdl, average length of field",
"details" : [ ]
}
]
}
]
}
]
},
{
"value" : 0.18794037,
"description" : "weight(content:student in 0) [PerFieldSimilarity], result of:",
"details" : [
{
"value" : 0.18794037,
"description" : "score(freq=5.0), computed as boost * idf * tf from:",
"details" : [
{
"value" : 2.2,
"description" : "boost",
"details" : [ ]
},
{
"value" : 0.105360515,
"description" : "idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:",
"details" : [
{
"value" : 4,
"description" : "n, number of documents containing term",
"details" : [ ]
},
{
"value" : 4,
"description" : "N, total number of documents with field",
"details" : [ ]
}
]
},
{
"value" : 0.8108108,
"description" : "tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:",
"details" : [
{
"value" : 5.0,
"description" : "freq, occurrences of term within document",
"details" : [ ]
},
{
"value" : 1.2,
"description" : "k1, term saturation parameter",
"details" : [ ]
},
{
"value" : 0.75,
"description" : "b, length normalization parameter",
"details" : [ ]
},
{
"value" : 13.0,
"description" : "dl, length of field",
"details" : [ ]
},
{
"value" : 13.5,
"description" : "avgdl, average length of field",
"details" : [ ]
}
]
}
]
}
]
}
]
},
{
"value" : 0.36464313,
"description" : "weight(EntityList:student in 0) [PerFieldSimilarity], result of:",
"details" : [
{
"value" : 0.36464313,
"description" : "score(freq=1.0), computed as boost * idf * tf from:",
"details" : [
{
"value" : 4.4,
"description" : "boost",
"details" : [ ]
},
{
"value" : 0.18232156,
"description" : "idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:",
"details" : [
{
"value" : 2,
"description" : "n, number of documents containing term",
"details" : [ ]
},
{
"value" : 2,
"description" : "N, total number of documents with field",
"details" : [ ]
}
]
},
{
"value" : 0.45454544,
"description" : "tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:",
"details" : [
{
"value" : 1.0,
"description" : "freq, occurrences of term within document",
"details" : [ ]
},
{
"value" : 1.2,
"description" : "k1, term saturation parameter",
"details" : [ ]
},
{
"value" : 0.75,
"description" : "b, length normalization parameter",
"details" : [ ]
},
{
"value" : 1.0,
"description" : "dl, length of field",
"details" : [ ]
},
{
"value" : 1.0,
"description" : "avgdl, average length of field",
"details" : [ ]
}
]
}
]
}
]
}
]
}
其中的boost = 2.2是下面公式中的k+1 = 1.2 + 1 =2.2组成,当我们在某个字段中加权时乘的是该值,例如我在两个字段,title和content字段中查询,并且title字段加权为1.1,则title字段中的得分会1.1*2.2 = 2.46。elasticsearch中通过multi-match查询多个字段时最后的排序会根据得分值为最高的字段的值进行排序。