我正在尝试理解弹性文档中的Explain API评分: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html
当我只用几个文档无法弄清楚我自己的简单索引时,我试图在上面的文档页面上重现计算。
在该示例中,它显示“值”1.3862944,其描述为:“idf,计算为log(1 +(docCount - docFreq + 0.5)/(docFreq + 0.5))”。在“详细信息”下,它为字段提供以下值:docFreq:1.0,docCount:5.0
使用提供的docFreq和docCount值,我将其计算为:log(1 +(5.0 - 1.0 + 0.5)/(1.0 + 0.5))= 0.602,这与示例中的1.3862944不同。
我无法获得任何匹配的值。
我读错了吗?
以下是整篇文章
GET /twitter/_doc/0/_explain
{
"query" : {
"match" : { "message" : "elasticsearch" }
}
}
这将产生以下结果:
{
"_index": "twitter",
"_type": "_doc",
"_id": "0",
"matched": true,
"explanation": {
"value": 1.6943599,
"description": "weight(message:elasticsearch in 0) [PerFieldSimilarity], result of:",
"details": [
{
"value": 1.6943599,
"description": "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:",
"details": [
{
"value": 1.3862944, <== This is the one I am trying
"description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
"details": [
{
"value": 1.0,
"description": "docFreq",
"details": []
},
{
"value": 5.0,
"description": "docCount",
"details": []
}
]
},
{
"value": 1.2222223,
"description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
"details": [
{
"value": 1.0,
"description": "termFreq=1.0",
"details": []
},
{
"value": 1.2,
"description": "parameter k1",
"details": []
},
{
"value": 0.75,
"description": "parameter b",
"details": []
},
{
"value": 5.4,
"description": "avgFieldLength",
"details": []
},
{
"value": 3.0,
"description": "fieldLength",
"details": []
}
]
}
]
}
]
}
}
答案 0 :(得分:3)
一如既往的解释非常准确,让我帮助您理解这些计算:
这是最初的公式:
log(1 + (5.0 - 1.0 + 0.5) / (1.0 + 0.5))
下一步将是:
log(1 + 4.5 / 1.5)
还有一个:
log(4) = ?
这是棘手的部分。您将此log
视为基数为10的日志。但是,如果您查看Lucene记分员的代码,您会发现它是ln
,这正是1.386294
部分代码:
public float idf(long docFreq, long numDocs) {
return (float)(Math.log(numDocs/(double)(docFreq+1)) + 1.0);
}
其中Math.log定义如下:
public static double log(double a)
Returns the natural logarithm (base e) of a double value.