- 44
- 0
示例索引结构:PUT /demo { "mappings":{ "properties":{ "color":{ "type":"keyword" }, "size":{ "type":"keyword" }, "price":{ "type":"double" } } }}测试数据:POST /demo/_doc{"color":"red","size":"large","price":100}POST /demo/_doc{"color":"blue","size":"large","price":500}POST /demo/_doc{"color":"red","size":"small","price":10}POST /demo/_doc{"color":"blue","size":"small","price":50}POST /demo/_doc{"color":"white","size":"small","price":1}POST /demo/_doc{"color":"white","size":"large","price":5}如果我想要找出每种颜色下面每种尺寸的价格平均值,且过滤平均值价格小于10的数据咋写呢?用SQL写的话就是:select avg(price) as avg_price from xxx group by color,size having avg_price > 10我目前写出来的查询DSL语句GET /demo/_search{ "size": 0, "aggregations": { "color_group": { "terms": { "field": "color" }, "aggregations": { "size_group": { "terms": { "field": "size" }, "aggregations": { "avg_price": { "avg": { "field": "price" } }, "price_bucket_filter": { "bucket_selector": { "buckets_path": { "avgPrice": "avg_price" }, "script": "params.avgPrice > 10" } } } } } } } } 得到的结果虽然把价格小于等于10的排除了,但是将会有一个空的分组,请问咋能把这个空的分组排除掉呢?结果如下: "aggregations": { "color_group": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "blue", "doc_count": 2, "size_group": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "large", "doc_count": 1, "avg_price": { "value": 500.0 } }, { "key": "small", "doc_count": 1, "avg_price": { "value": 50.0 } } ] } }, { "key": "red", "doc_count": 2, "size_group": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "large", "doc_count": 1, "avg_price": { "value": 100.0 } } ] } }, { "key": "white", // 希望去掉这个空的结果 "doc_count": 2, "size_group": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [] } } ] } }}
0
打赏
收藏
点击回答
网站公告
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部

