Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
<img src="//i.stack.imgur.com/RUiNP.png" height="16" width="18" alt="" class="sponsor tag img">elasticsearch 弹性搜索_聚合中的分数为空。为什么?_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Full Text Search_Aggregation_Relevance - Fatal编程技术网 elasticsearch 弹性搜索_聚合中的分数为空。为什么?,elasticsearch,full-text-search,aggregation,relevance,elasticsearch,Full Text Search,Aggregation,Relevance" /> elasticsearch 弹性搜索_聚合中的分数为空。为什么?,elasticsearch,full-text-search,aggregation,relevance,elasticsearch,Full Text Search,Aggregation,Relevance" />

elasticsearch 弹性搜索_聚合中的分数为空。为什么?

elasticsearch 弹性搜索_聚合中的分数为空。为什么?,elasticsearch,full-text-search,aggregation,relevance,elasticsearch,Full Text Search,Aggregation,Relevance,我使用ESV1.7。ES只在“点击数”部分返回_分数,但我对“点击数”不感兴趣,我需要Response中带有_分数的“聚合”部分的数据。为什么会这样?如何解决 请求: { "size": 1, "query": { "bool": { "must": [ { "match": {"_all": {"query": "test","operator": "and","fuzzin

我使用ESV1.7。ES只在“点击数”部分返回_分数,但我对“点击数”不感兴趣,我需要Response中带有_分数的“聚合”部分的数据。为什么会这样?如何解决

请求:

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

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

因为您使用的是sort,所以需要为要计算的分数显式设置“”

例如:

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


}

下面的答案无效吗?