一尘不染

Elasticsearch聚合排名(按热门得分)

elasticsearch

我想按top_hit的doc.score订购存储桶。我当前的实现如下。

  group_by_iid: {
    terms: {
      field: 'iid',
      order: { max_score: 'desc' },
      size: 0
    },
    aggs: {
      max_score: { max: { script: 'doc.score' } },
      top_hit: {
        top_hits: {
          sort: [{ source_priority: { order: 'desc' } }],
          size: 1
        }
      }
    }
  }

这是错误的,因为存储桶是按其最高得分而不是其source_priority文档最高得分排序的。有办法解决这个问题吗?


阅读 1146

收藏
2020-06-22

共1个答案

一尘不染

我遇到了同样的问题,而解决问题的方法是在docs得分上引入子汇总。然后在我的外部聚合中,我按max_score聚合的名称排序。

GET /my-index/my-type/_search
{
  "query": {
      "bool" : {
        "should" : [ {
          "match" : {
            "searchTerm" : {
              "query" : "style",
              "type" : "boolean"
            }
          }
        }, 
        {
          "flt_field" : {
            "searchTerm" : {
              "like_text" : "style"
            }
          }
        }]
      }
    },
    "aggs": {
        "group_by_target_url": {
          "terms": {
            "field": "targetUrl",
            "order": {
              "max_score": "desc"
            }
          },
          "aggs": {
            "max_score": {
              "max": {
                "script": "doc.score"
              }
            }
          }
    }
  }    
}

我遵循了此链接上的指示:

http://www.elasticsearch.org/guide/zh-
CN/elasticsearch/reference/current/search-aggregations-bucket-terms-
aggregation.html

2020-06-22