V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
unbright
V2EX  ›  Java

咨询下各位大佬 ES 聚合排序的问题

  •  
  •   unbright · 2021-03-09 16:58:20 +08:00 · 1308 次点击
    这是一个创建于 1136 天前的主题,其中的信息可能已经有所发展或是发生改变。

    es 是不是不能能 AggregationBuilders.terms 的字段进行排序,用了后报这个错。 Buckets can only be sorted on a sub-aggregator path that is built out of zero or more single-bucket aggregations within the path and a final single-bucket or a metrics aggregation at the path end

    第 1 条附言  ·  2021-03-10 14:30:16 +08:00
    这个是查询条件,排序后的结果和期望的不一样,通过 trace_no 分组,用求和的 order_money 来排序
    {
    "query": {
    "bool": {
    "filter": [{
    "term": {
    "order_market_id": {
    "value": "1828"
    }
    }
    }, {
    "term": {
    "member_id": {
    "value": "0012695142"
    }
    }
    }]
    }
    },
    "aggregations": {
    "agg": {
    "terms": {
    "field": "trace_no",
    "size": 2147483647,
    "order": {
    "latestOrder": "desc"
    }
    },
    "aggregations": {
    "latestOrder": {
    "sum": {
    "field": "order_money"
    }
    },
    "top": {
    "top_hits": {
    "version": false,
    "seq_no_primary_term": false,
    "explain": false,
    "_source": {
    "includes": [
    "order_time","order_money","trace_no","card_no","bill_no","member_id","sku_name"
    ],
    "excludes": [

    ]
    }
    }
    },
    "bucket_field": {
    "bucket_sort": {
    "sort": [{
    "latestOrder": {
    "order": "desc"
    }
    }],
    "from": 0,
    "size": 10
    }
    }
    }
    }
    }
    }
    5 条回复    2021-03-11 11:26:10 +08:00
    456789
        1
    456789  
       2021-03-10 10:36:24 +08:00
    插眼问下 有没有好的使用 es 的例子,主要是对 RestHighLevelClient 的关闭管理这里想看看有没有好的
    sonice
        2
    sonice  
       2021-03-10 14:20:10 +08:00   ❤️ 1
    @456789 #1 client 官方是推荐单例的,不要重复去开关。可以自己控制 io thread 数量来控制并发。
    sinux
        3
    sinux  
       2021-03-10 14:22:58 +08:00
    没 query 不太懂想怎么排序。建议看看 bucket sort aggregation 那部分 。
    unbright
        4
    unbright  
    OP
       2021-03-10 14:31:11 +08:00
    @sinux 用的 bucket_sort,补充了 dsl,大佬看下哪里有问题
    sinux
        5
    sinux  
       2021-03-11 11:26:10 +08:00
    @unbright #4 请问解决了吗?想知道究竟是哪里的问题.....
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3194 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 14:04 · PVG 22:04 · LAX 07:04 · JFK 10:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.