如何计算Elasticsearch相关性得分?

时间:2017-11-20 13:42:19

标签: elasticsearch elasticsearch-5

我在multi_match使用phrase_prefix进行Elasticsearch 5.5中的全文搜索。 ES查询看起来像

{
  query: {
    bool: {
      must: {
        multi_match: {
          query: "butt", 
          type: "phrase_prefix", 
          fields: ["item.name", "item.keywords"], 
          max_expansions: 10
        }
      }
    }
  }
}

我收到了以下回复

[
  {
    "_index": "items_index",
    "_type": "item",
    "_id": "2",
    "_score": 0.61426216,
    "_source": {
      "item": {
        "keywords": "amul butter, milk, butter milk, flavoured",
        "name": "Flavoured Butter"
       }
     }
   },
   {
     "_index": "items_index",
     "_type": "item",
     "_id": "1",
     "_score": 0.39063013,
     "_source": {
       "item": {
         "keywords": "amul butter, milk, butter milk",
         "name": "Butter Milk"
       }
     }
   }
 ]

映射如下(我使用的是默认映射)

 {
   "items_index" : {
     "mappings" : {
       "parent_doc": {
         ...
         "properties": {
           "item" : {
             "properties" : {
               "keywords" : {
                 "type" : "text",
                 "fields" : {
                   "keyword" : {
                     "type" : "keyword",
                     "ignore_above" : 256
                   }
                 }
               },
               "name" : {
                 "type" : "text",
                 "fields" : {
                   "keyword" : {
                     "type" : "keyword",
                     "ignore_above" : 256
                   }
                 }
               }
             }
           } 
         }
       }
     }
 } 

item "name": "Flavoured Butter" 0.61426216"name": "Butter Milk"0.39063013的文档得分越高"item.name"的方式如何?

我尝试将提升应用于"item.keywords"并删除constructor(private http:Http){ let _build = (<any>this.http)._backend._browseXHR.build; (<any>this.http)._backend._browseXHR.build = () => { let _xhr = _build(); _xhr.withCredentials = true; return (_xhr); }; } 表单搜索字段,以获得相同的结果。

Elasticsearch的得分如何运作?上述结果在相关性方面是否正确?

1 个答案:

答案 0 :(得分:0)

phrase_prefix的得分与best_fields的得分相似,这意味着文档得分是从best_field获得的得分,此处为item.keywords

因此,item.name没有添加到分数

参考:multi-match-types

您可以使用2 multi_match个查询来合并keywordsname的分数。

{
   "query": {
      "bool": {
         "must": [{
            "multi_match": {
               "query": "butt",
               "type": "phrase_prefix",
               "fields": [
                  "item.keywords"
               ],
               "max_expansions": 10
            }
         },{
            "multi_match": {
               "query": "butt",
               "type": "phrase_prefix",
               "fields": [
                  "item.name"
               ],
               "max_expansions": 10
            }
         }]
      }
   }
}