弹性搜索。聚合中_Score为空。为什么? [英] Elastic Search. _Score is null in aggregations. Why?

查看:234
本文介绍了弹性搜索。聚合中_Score为空。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ES v 1.7。 ES仅在点击部分返回_score,但我对点击不感兴趣,因此我需要使用_score 响应的聚合部分的数据。为什么ES这样做和如何解决它?



Requset:

<$ p
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:或
boost:3
}}
]
}
},
aggs:{
byObjectID:{
terms :{field:ObjectID},
aggs:{
latestVer:{
top_hits:{
sort:[{creationDate:{order:desc}}]
,_ source:{包括:[ObjectData.BRIEFNAME,creationDate,ObjectID]}
,size:1
}
}
}
}


回应:

  {
took:16,
timed_out:false,
_shards: {
total:5,
success:5,
failed:0
},
hits:{
总数:87,
max_score:5.3479624,
hits:[{
_index:crmws,
_type:participant b $ b_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
hits:[{
_index:crmws,
_type:participant,
_id:AVFtQCCtSH3HWHh0wItF,
_score:null,
_source:{
creationDate:2015-12-04T13:48:17.949Z,
ObjectID:26745417,
ObjectData:{BRIEFNAME:Верный-ПреверныйВ. }
},
sort:[1449236897949]
}]
}}
},
...
]
}}
}


解决方案

由于您使用排序,您需要明确设置
prenofollow> track_scores
用于计算得分。 > {
size:1,
query:{
bool:{
must:[
{ match:{_all:{query:test,operator:and,fuzziness:2}}}
],
should: [
{multi_match:{
query:test
,type:best_fields
,f ields:[ObjectData.PRTNAME,ObjectData.EXTERNALID,ObjectData.contactList.VALUE,* SERIES,* NUMBER,ObjectData.INN]
,operator:或
,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
}
}
}
}
}


}


I use ES v 1.7. ES returns _score just only in "hits" section, but i'm not interested in "hits", I need data from "aggregations" section of responce with _score. Why ES do like that and How to fix it?

Requset:

{
    "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
          }
        }
      }
    }
  }
}

Response:

{
   "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]
               }]
            }}
         },
         ...
      ]
   }}
}

解决方案

Since you are using sort you would need to explicitly set "track_scores" for scores to be computed.

Example:

{
    "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
          }
        }
      }
    }
  }


}

这篇关于弹性搜索。聚合中_Score为空。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆