【问题标题】:Understand elasticsearch query explain了解elasticsearch查询说明
【发布时间】:2018-09-06 07:25:18
【问题描述】:

我正在尝试了解弹性文档中的解释 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": []
                 }
              ]
           }
        ]
     }
  ]
}
}

【问题讨论】:

    标签: elasticsearch explain


    【解决方案1】:

    解释一如既往的准确,让我帮你理解那些计算:

    这是初始公式:

    log(1 + (5.0 - 1.0 + 0.5) / (1.0 + 0.5))
    

    下一步是:

    log(1 + 4.5 / 1.5)
    

    还有一个:

    log(4) = ?
    

    这里是棘手的部分。您将此log 视为以10 为底的日志。但是,如果您查看Lucene scorer 的代码,您会发现它是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.
    

    【讨论】:

      猜你喜欢
      • 2016-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多