通过子聚集结果值对术语聚集桶进行排序

编程入门 行业动态 更新时间:2024-10-22 12:29:42
本文介绍了通过子聚集结果值对术语聚集桶进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

关于此捕获显示的查询,我有两个问题:

I have two questions about the query seen on this capture:

  • 如何按 value ? 我在查询中再次使用 respsize ,但是如下所示,它是不正确的。

  • How do I order by value in the sum_category field in the results? I use respsize again in the query but it's not correct as you can see below.

    即使我仅进行了汇总,为什么所有文档都附带结果?我的意思是,如果我在SQL中进行 group by 查询,它将仅检索分组的数据,但是Elasticsearch检索所有文档,就像我进行常规搜索查询一样。我怎么跳过它们?

    Even if I make only an aggregration, why do all the documents come with the result? I mean, if I make a group by query in SQL it retrieves only grouped data, but Elasticsearch retrieves all documents as if I made a normal search query. How do I skip them?

    推荐答案

    尝试一下:

    { "query" : { "match_all" : {} }, "size" : 0, "aggs" : { "categories" : { "terms" : { "field" : "category", "size" : 999999, "order" : { "sum_category" : "desc" } }, "aggs" : { "sum_category" : { "sum" : { "field" : "respsize" } } } } } }

    1)。有关您的排序的操作,请参见(2)中的注释。至于按sum_category的值对类别进行排序,请参见 order 部分。似乎存在与该 github/elastic/elasticsearch相关的古老且封闭的问题/ issues / 4643 ,但在Elasticsearch v1.5.2版本中对我来说效果很好。

    1). See the note in (2) for what your sort is doing. As for ordering the categories by the value of sum_category, see the order portion. There appears to be an old and closed issue related to that github/elastic/elasticsearch/issues/4643 but it worked fine for me with v1.5.2 of Elasticsearch.

    2)。尽管您没有该match_all查询,但我认为这可能是您得到的结果。因此,您指定的排序实际上已应用于这些结果。为了不让它们回来,我只提供了 size:0 部分。

    2). Although you do not have that match_all query, I think that's probably what you are getting results for. And so the sort your specified is actually getting applied to those results. To not get these back, I just have size: 0 portion.

    是否要为所有类别使用存储桶?我注意到您没有为主要集合指定大小。这就是 size:999999 部分。

    Do you want buckets for all the categories? I noticed you do not have size specified for the main aggregation. That's the size: 999999 portion.

  • 更多推荐

    通过子聚集结果值对术语聚集桶进行排序

    本文发布于:2023-11-22 05:38:02,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1616172.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:术语

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!