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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

白话Elasticsearch41-深入聚合数据分析之案例实战__过滤+聚合:统计价格大于2000的电视平均价格

發布時間:2025/3/21 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 白话Elasticsearch41-深入聚合数据分析之案例实战__过滤+聚合:统计价格大于2000的电视平均价格 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 概述
  • 案例


概述

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

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


案例

需求: 統計價格大于2000的電視的平均價格

原始數據:

不多說了,很簡單,只需要在查詢的時候過濾下即可

GET /tvs/sales/_search {"query": {"range": {"price": {"gte": "2000"}}},"aggs": {"avg_price": {"avg": {"field": "price"}}},"size": 0 }

返回結果:

{"took": 7,"timed_out": false,"_shards": {"total": 5,"successful": 5,"skipped": 0,"failed": 0},"hits": {"total": 5,"max_score": 0,"hits": []},"aggregations": {"avg_price": {"value": 3500}} }

我們把原始數據也返回(去掉 "size": 0),來校驗下,是否正確。

GET /tvs/sales/_search {"query": {"range": {"price": {"gte": "2000"}}},"aggs": {"avg_price": {"avg": {"field": "price"}}} }

返回:

{"took": 27,"timed_out": false,"_shards": {"total": 5,"successful": 5,"skipped": 0,"failed": 0},"hits": {"total": 5,"max_score": 1,"hits": [{"_index": "tvs","_type": "sales","_id": "QzGrtGwBCp8vhw_gCmb9","_score": 1,"_source": {"price": 2000,"color": "紅色","brand": "長虹","sold_date": "2016-11-05"}},{"_index": "tvs","_type": "sales","_id": "PzGrtGwBCp8vhw_gCmb9","_score": 1,"_source": {"price": 2000,"color": "紅色","brand": "長虹","sold_date": "2016-11-05"}},{"_index": "tvs","_type": "sales","_id": "QDGrtGwBCp8vhw_gCmb9","_score": 1,"_source": {"price": 3000,"color": "綠色","brand": "小米","sold_date": "2016-05-18"}},{"_index": "tvs","_type": "sales","_id": "RDGrtGwBCp8vhw_gCmb9","_score": 1,"_source": {"price": 8000,"color": "紅色","brand": "三星","sold_date": "2017-01-01"}},{"_index": "tvs","_type": "sales","_id": "RTGrtGwBCp8vhw_gCmb9","_score": 1,"_source": {"price": 2500,"color": "藍色","brand": "小米","sold_date": "2017-02-12"}}]},"aggregations": {"avg_price": {"value": 3500}} }

比對下原始數據,可知正確。

總結

以上是生活随笔為你收集整理的白话Elasticsearch41-深入聚合数据分析之案例实战__过滤+聚合:统计价格大于2000的电视平均价格的全部內容,希望文章能夠幫你解決所遇到的問題。

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