ElasticSearch评分问题

时间:2014-04-13 10:46:36

标签: elasticsearch indexing nosql

我正在试图找出ElasticSearch在按分数对结果进行排名时使用的逻辑。

我总共有4个索引。我正在查询一个学期的所有索引。我正在使用的查询如下 -

GET /_all/static/_search
{
  "query": {
    "match": {
      "name": "chinese"
    }
  }
}

我得到的(部分)响应如下 -

    {
   "took": 17,
   "timed_out": false,
   "_shards": {
      "total": 40,
      "successful": 40,
      "failed": 0
   },
   "hits": {
      "total": 6,
      "max_score": 2.96844,
      "hits": [
         {
            "_shard": 1,
            "_node": "Hz9L2DZ-ShSajaNvoyU8Eg",
            "_index": "restaurant",
            "_type": "static",
            "_id": "XecLkyYNQWihuR2atFc5JQ",
            "_score": 2.96844,
            "_source": {
               "name": "Just Chinese"
            },
            "_explanation": {
               "value": 2.96844,
               "description": "weight(name:chinese in 1) [PerFieldSimilarity], result of:",
               "details": [
                  {
                     "value": 2.96844,
                     "description": "fieldWeight in 1, product of:",
                     "details": [
                        {
                           "value": 1,
                           "description": "tf(freq=1.0), with freq of:",
                           "details": [
                              {
                                 "value": 1,
                                 "description": "termFreq=1.0"
                              }
                           ]
                        },
                        {
                           "value": 4.749504,
                           "description": "idf(docFreq=3, maxDocs=170)"
                        },
                        {
                           "value": 0.625,
                           "description": "fieldNorm(doc=1)"
                        }
                     ]
                  }
               ]
            }
         },
         {
            "_shard": 1,
            "_node": "Hz9L2DZ-ShSajaNvoyU8Eg",
            "_index": "restaurant",
            "_type": "static",
            "_id": "IAUpkC55ReySjvl9Xr5MVw",
            "_score": 2.96844,
            "_source": {
               "name": "The Chinese Hut"
            },
            "_explanation": {
               "value": 2.96844,
               "description": "weight(name:chinese in 5) [PerFieldSimilarity], result of:",
               "details": [
                  {
                     "value": 2.96844,
                     "description": "fieldWeight in 5, product of:",
                     "details": [
                        {
                           "value": 1,
                           "description": "tf(freq=1.0), with freq of:",
                           "details": [
                              {
                                 "value": 1,
                                 "description": "termFreq=1.0"
                              }
                           ]
                        },
                        {
                           "value": 4.749504,
                           "description": "idf(docFreq=3, maxDocs=170)"
                        },
                        {
                           "value": 0.625,
                           "description": "fieldNorm(doc=5)"
                        }
                     ]
                  }
               ]
            }
         },
         {
            "_shard": 2,
            "_node": "Hz9L2DZ-ShSajaNvoyU8Eg",
            "_index": "cuisine",
            "_type": "static",
            "_id": "6",
            "_score": 2.7047482,
            "_source": {
               "name": "Chinese"
            },
            "_explanation": {
               "value": 2.7047482,
               "description": "weight(name:chinese in 1) [PerFieldSimilarity], result of:",
               "details": [
                  {
                     "value": 2.7047482,
                     "description": "fieldWeight in 1, product of:",
                     "details": [
                        {
                           "value": 1,
                           "description": "tf(freq=1.0), with freq of:",
                           "details": [
                              {
                                 "value": 1,
                                 "description": "termFreq=1.0"
                              }
                           ]
                        },
                        {
                           "value": 2.7047482,
                           "description": "idf(docFreq=1, maxDocs=11)"
                        },
                        {
                           "value": 1,
                           "description": "fieldNorm(doc=1)"
                        }
                     ]
                  }
               ]
            }
         },

我的问题是 - 我理解弹性搜索以更高的分数处理较小的值,那么为什么来自餐馆指数的“Just Chinese”和“The Chinese Hut”的结果排在预期的最佳匹配“中国”之上来自美食指数?据我所知,在将这些文档插入索引时,我没有使用任何特殊的分析仪或任何东西。一切都是默认的。

我错过了什么以及如何获得预期结果?

1 个答案:

答案 0 :(得分:3)

计算分数的一个重要参数是inverse document frequency(IDF)。默认情况下,elasticsearch的每个分片都会尝试根据本地IDF估计全局IDF。当你有很多相似的记录在分片中均匀分布时,它就可以工作。但是,如果您只有几条记录,或者当您将多个分片的结果与不同类型的记录(菜肴名称和餐馆名称)相结合时,估计IDF可能会产生奇怪的结果。此问题的解决方案是使用弹性搜索的dfs_query_then_fetch搜索模式。

顺便说一句,为了理解elasticsearch如何计算得分,您可以在搜索请求或网址上使用explain参数。因此,当您询问有关评分的问题时,在将输出解释设置为true时会有所帮助。