简体   繁体   English

按最高命中分数的弹性搜索聚合顺序

[英]Elasticsearch aggregation order by top hit score

I want to order buckets by doc.score of top_hit. 我想通过top_hit的doc.score订购存储桶。 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
        }
      }
    }
  }

This is wrong because buckets are ordered by their top score, not their top source_priority document's score. 这是错误的,因为存储桶按其最高分排序,而不是按其最高source_priority文档的分数排序。 Is there a way to solve this problem? 有没有办法解决这个问题?

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. 然后在我的外部聚合中,我按照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"
              }
            }
          }
    }
  }    
}

I followed the directions on this link: 我按照此链接上的说明操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM