Elasticsearch聚合排名(按热门得分) [英] Elasticsearch aggregation order by top hit score

查看:644
本文介绍了Elasticsearch聚合排名(按热门得分)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to order buckets by doc.score of top_hit. My current implementation is below.

  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文档中得分最高的分数。有解决这个问题的方法吗?

This is wrong because buckets are ordered by their top score, not their top source_priority document's score. Is there a way to solve this problem?

推荐答案

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

I had the same issue, and the way I resolved it was to introduce a sub-aggregation on the docs score. Then in my outer aggregation, I ordered by name of the max_score aggregation.

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

这篇关于Elasticsearch聚合排名(按热门得分)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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