日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

白话Elasticsearch44-深入聚合数据分析之案例实战_颜色+品牌下钻分析时按最深层metric进行排序

發布時間:2025/3/21 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 白话Elasticsearch44-深入聚合数据分析之案例实战_颜色+品牌下钻分析时按最深层metric进行排序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 概述
  • 案例


概述

繼續跟中華石杉老師學習ES,第44篇

課程地址: https://www.roncoo.com/view/55


案例

需求: 顏色+品牌下鉆分析時按最深層metric進行排序

先看下默認的排序規則:

GET /tvs/sales/_search {"aggs": {"group_by_color": {"terms": {"field": "color"},# 在color這個bucket下 下鉆 品牌"aggs": {"group_by_brand": {"terms": {"field": "brand"},# 在brand這個b下 bcketmetrics 求 avg"aggs": {"avg_price": {"avg": {"field": "price"}}}}}}},"size": 0 }

返回:

{"took": 1,"timed_out": false,"_shards": {"total": 5,"successful": 5,"skipped": 0,"failed": 0},"hits": {"total": 8,"max_score": 0,"hits": []},"aggregations": {"group_by_color": {"doc_count_error_upper_bound": 0,"sum_other_doc_count": 0,"buckets": [{"key": "紅色","doc_count": 4,"group_by_brand": {"doc_count_error_upper_bound": 0,"sum_other_doc_count": 0,"buckets": [{"key": "長虹","doc_count": 3,"avg_price": {"value": 1666.6666666666667}},{"key": "三星","doc_count": 1,"avg_price": {"value": 8000}}]}},{"key": "綠色","doc_count": 2,"group_by_brand": {"doc_count_error_upper_bound": 0,"sum_other_doc_count": 0,"buckets": [{"key": "TCL","doc_count": 1,"avg_price": {"value": 1200}},{"key": "小米","doc_count": 1,"avg_price": {"value": 3000}}]}},{"key": "藍色","doc_count": 2,"group_by_brand": {"doc_count_error_upper_bound": 0,"sum_other_doc_count": 0,"buckets": [{"key": "TCL","doc_count": 1,"avg_price": {"value": 1500}},{"key": "小米","doc_count": 1,"avg_price": {"value": 2500}}]}}]}} }

截取下Red 來看下默認的排序規則 (doc_count 降序)


如果想按照平均價格 降序排列呢? 我們這里有2層下鉆,而平均價格是在第二層下鉆里 ,即我們這里的主題【按最深層metric進行排序】

GET /tvs/sales/_search {"aggs": {"group_by_color": {"terms": {"field": "color"},"aggs": {"group_by_brand": {"terms": {"field": "brand","order": {"avg_price": "desc"}},"aggs": {"avg_price": {"avg": {"field": "price"}}}}}}},"size": 0 }

返回結果:

{"took": 2,"timed_out": false,"_shards": {"total": 5,"successful": 5,"skipped": 0,"failed": 0},"hits": {"total": 8,"max_score": 0,"hits": []},"aggregations": {"group_by_color": {"doc_count_error_upper_bound": 0,"sum_other_doc_count": 0,"buckets": [{"key": "紅色","doc_count": 4,"group_by_brand": {"doc_count_error_upper_bound": 0,"sum_other_doc_count": 0,"buckets": [{"key": "三星","doc_count": 1,"avg_price": {"value": 8000}},{"key": "長虹","doc_count": 3,"avg_price": {"value": 1666.6666666666667}}]}},{"key": "綠色","doc_count": 2,"group_by_brand": {"doc_count_error_upper_bound": 0,"sum_other_doc_count": 0,"buckets": [{"key": "小米","doc_count": 1,"avg_price": {"value": 3000}},{"key": "TCL","doc_count": 1,"avg_price": {"value": 1200}}]}},{"key": "藍色","doc_count": 2,"group_by_brand": {"doc_count_error_upper_bound": 0,"sum_other_doc_count": 0,"buckets": [{"key": "小米","doc_count": 1,"avg_price": {"value": 2500}},{"key": "TCL","doc_count": 1,"avg_price": {"value": 1500}}]}}]}} }

同樣的,我們也截取下Red 來看下默認的排序規則 (doc_count 降序)

已經按照我們指定的 avg_price 降序排列啦。

總結

以上是生活随笔為你收集整理的白话Elasticsearch44-深入聚合数据分析之案例实战_颜色+品牌下钻分析时按最深层metric进行排序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。