elasticsearch - Elasticsearch 。 _Score 在聚合中为 null。为什么?

标签 elasticsearch full-text-search aggregation relevance

我使用 ES v 1.7。 ES 仅在“hits”部分返回 _score,但我对“hits”不感兴趣,我需要来自 with _score 响应的“aggregations”部分的数据。为什么 ES 会这样以及如何解决?

请求:

{
    "size": 1,
        "query": {
            "bool": {
                "must": [
                    { "match": {"_all": {"query": "test","operator": "and","fuzziness": "2"}}}
                ],
                "should": [
                    { "multi_match" : {
                            "query":      "test"
                            ,"type":       "best_fields"
                            ,"fields":     ["ObjectData.PRTNAME","ObjectData.EXTERNALID","ObjectData.contactList.VALUE","*SERIES","*NUMBER","ObjectData.INN"]
                            ,"operator":   "or"
                            ,"boost": 3
                    }}
                ]
            } 
        },   
  "aggs": {
    "byObjectID": {
      "terms": {"field": "ObjectID"},
      "aggs": {
        "latestVer": {
          "top_hits": {
            "sort": [{"creationDate": { "order": "desc" }}]
            ,"_source": { "include": ["ObjectData.BRIEFNAME", "creationDate", "ObjectID" ]}
            ,"size": 1
          }
        }
      }
    }
  }
}

响应:

{
   "took": 16,
   "timed_out": false,
   "_shards":    {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits":    {
      "total": 87,
      "max_score": 5.3479624,
      "hits": [      {
         "_index": "crmws",
         "_type": "participant",
         "_id": "AVFtAkIcSH3HWHh0wIkd",
         "_score": 5.3479624,
         "_source":          {
            "mostRecentVersion": null,
            "UserLogin": "ap",
            "creationDate": "2015-12-04T12:40:43.292Z",
            "_id": null,
            "ObjectID": 26784418,
            "EventID": null,
            "version_id": 3798,
            "ObjectTypeId": null,
            "ObjectData":   {...},
            "ObjectTypeSysName": "participant",
            "versionNumber": null
         }
      }]
   },
   "aggregations": {"byObjectID":    {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets":       [
                  {
            "key": 26745417,
            "doc_count": 21,
            "latestVer": {"hits":             {
               "total": 21,
               "max_score": null,
               "hits": [               {
                  "_index": "crmws",
                  "_type": "participant",
                  "_id": "AVFtQCCtSH3HWHh0wItF",
                  "_score": null,
                  "_source":                   {
                     "creationDate": "2015-12-04T13:48:17.949Z",
                     "ObjectID": 26745417,
                     "ObjectData": {"BRIEFNAME": "Верный-Преверный В. В."}
                  },
                  "sort": [1449236897949]
               }]
            }}
         },
         ...
      ]
   }}
}

最佳答案

由于您正在使用排序,因此您需要明确设置“track_scores”才能计算分数。

例子:

{
    "size": 1,
        "query": {
            "bool": {
                "must": [
                    { "match": {"_all": {"query": "test","operator": "and","fuzziness": "2"}}}
                ],
                "should": [
                    { "multi_match" : {
                            "query":      "test"
                            ,"type":       "best_fields"
                            ,"fields":     ["ObjectData.PRTNAME","ObjectData.EXTERNALID","ObjectData.contactList.VALUE","*SERIES","*NUMBER","ObjectData.INN"]
                            ,"operator":   "or"
                            ,"boost": 3
                    }}
                ]
            } 
        },   
  "aggs": {
    "byObjectID": {
      "terms": {"field": "ObjectID"},
      "aggs": {
        "latestVer": {
          "top_hits": {
            "sort": [{"creationDate": { "order": "desc" }}]
            ,"_source": { "include": ["ObjectData.BRIEFNAME", "creationDate", "ObjectID" ]}
            ,"size": 1,
            'track_scores" : 1
          }
        }
      }
    }
  }


}

关于elasticsearch - Elasticsearch 。 _Score 在聚合中为 null。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34175750/

相关文章:

c++ - 如何向我的应用程序添加搜索功能

iphone - 如何统计coredata(聚合)?

elasticsearch - 如何在 bool 每次匹配中准确返回一个文档

Elasticsearch,获取平均文档长度

ruby-on-rails - Sphinx 增量索引——仍然需要重建主索引吗?

sql-server-2008 - SQL Server 2008 中的全文邻近和最大距离语法

elasticsearch - 在ElasticSearch中不带映射的带斜杠的值的术语过滤器

elasticsearch - Elasticsearch 和Spark

两个时间序列的python聚合

c++ - 对象验证灵活性设计 : aggregation vs composition