白话Elasticsearch41-深入聚合数据分析之案例实战__过滤+聚合:统计价格大于2000的电视平均价格
生活随笔
收集整理的這篇文章主要介紹了
白话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的电视平均价格的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 白话Elasticsearch40-深入
- 下一篇: 白话Elasticsearch42-深入