Elasticsearch 聚合顺序按最高命中分数

标签 elasticsearch aggregation

我想按 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 文档的得分排序的。有没有办法解决这个问题?

最佳答案

我有同样的问题,我解决它的方法是在文档分数上引入一个子聚合。然后在我的外部聚合中,我按 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": "_score"
          }
        }
      }
    }
  }
}

我按照此链接上的说明操作:

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

关于Elasticsearch 聚合顺序按最高命中分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26213271/

相关文章:

api - Elasticsearch API返回的文档数量相同

elasticsearch - Elasticsearch:聚合准确性

MongoDB $sort(聚合)不起作用

MongoDB 聚合 - 如果提供其他不匹配,则匹配输入参数

elasticsearch - 设置 elasticsearch 对象的 "index"属性

json - logstash:使用一个logstash conf文件创建多个索引

php - Elasticsearch 多个查询

c# - MongoDB 组到 C# API

javascript - 如何在 Omniture (SiteCatalyst) 中为网站部分创建自定义路径定义和过滤器?

amazon-web-services - AWS Elasticsearch : How to move data from one index into another