弹性搜索。_Score 在聚合中为空。为什么?

Ily*_*a P 3 full-text-search aggregation relevance elasticsearch

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

\n\n

要求:

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

回复:

\n\n
{\n   "took": 16,\n   "timed_out": false,\n   "_shards":    {\n      "total": 5,\n      "successful": 5,\n      "failed": 0\n   },\n   "hits":    {\n      "total": 87,\n      "max_score": 5.3479624,\n      "hits": [      {\n         "_index": "crmws",\n         "_type": "participant",\n         "_id": "AVFtAkIcSH3HWHh0wIkd",\n         "_score": 5.3479624,\n         "_source":          {\n            "mostRecentVersion": null,\n            "UserLogin": "ap",\n            "creationDate": "2015-12-04T12:40:43.292Z",\n            "_id": null,\n            "ObjectID": 26784418,\n            "EventID": null,\n            "version_id": 3798,\n            "ObjectTypeId": null,\n            "ObjectData":   {...},\n            "ObjectTypeSysName": "participant",\n            "versionNumber": null\n         }\n      }]\n   },\n   "aggregations": {"byObjectID":    {\n      "doc_count_error_upper_bound": 0,\n      "sum_other_doc_count": 0,\n      "buckets":       [\n                  {\n            "key": 26745417,\n            "doc_count": 21,\n            "latestVer": {"hits":             {\n               "total": 21,\n               "max_score": null,\n               "hits": [               {\n                  "_index": "crmws",\n                  "_type": "participant",\n                  "_id": "AVFtQCCtSH3HWHh0wItF",\n                  "_score": null,\n                  "_source":                   {\n                     "creationDate": "2015-12-04T13:48:17.949Z",\n                     "ObjectID": 26745417,\n                     "ObjectData": {"BRIEFNAME": "\xd0\x92\xd0\xb5\xd1\x80\xd0\xbd\xd1\x8b\xd0\xb9-\xd0\x9f\xd1\x80\xd0\xb5\xd0\xb2\xd0\xb5\xd1\x80\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\x92. \xd0\x92."}\n                  },\n                  "sort": [1449236897949]\n               }]\n            }}\n         },\n         ...\n      ]\n   }}\n}\n
Run Code Online (Sandbox Code Playgroud)\n

kee*_*ety 5

由于您正在使用排序,因此您需要显式设置“ 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
          }
        }
      }
    }
  }


}
Run Code Online (Sandbox Code Playgroud)