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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

01.elasticsearch metric aggregation 查询

發布時間:2024/2/28 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 01.elasticsearch metric aggregation 查询 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

    • 1. 數據準備
    • 2. metric aggregation分類
    • 3.使用樣例
      • 1 . Avg Aggregation : 求query出來的結果的average 值
      • 2 . Weighted Avg Aggregation: 帶權重的average值,可以選取另一個字段的值作為權重值
      • 3 . Max Aggregation: 求query出來的結果的max值
      • 4 . Min Aggregation: 求query出來的結果的min值
      • 5 . Sum Aggregation: 求query出來的結果的sum值
      • 6 . Value Count Aggregation: query出來的結果的某個field的的值的個數,注意可能這個field的值是一個數組則這個一個doc可能就貢獻了多個value count
      • 7 . Cardinality Aggregation: 某個filed的value去重后的count, 可以理解為value_count做了去重
      • 8 . Percentiles Aggregation: 百分比求值,對于大小的數值,求百分位,比如響應時間的99分位,95分位等對應的具體響應時間是多少
      • 9 . Percentile Ranks Aggregation: 某個具體的響應時間在總體中所處的分位值
      • 10. Stats Aggregation: 上面value_count,min,max,sum,avg的快捷方式
      • 11. top_hit

elasticsearch的aggregate查詢現在越來越豐富了,目前總共有4類。

  • metric aggregation: 主要是min,max,avg,sum,percetile 等單個統計指標的查詢,同時,可以用作bucket agg的子聚合查詢,但是本身不能包含子查詢
  • bucket aggregation: 主要是類似group by的查詢操作,而且可以含有子查詢
  • matrix aggregation: 使用多個字段的值進行計算從而產生一個多維矩陣
  • pipline aggregation: 主要是能夠在其他的aggregation進行一些附加的處理來增強數據
  • 本篇就主要學習metric aggregation

    1. 數據準備

    演唱會的票信息
    GET seats1028/_search

    { "play" : "Auntie Jo", # 演唱會名稱 "date" : "2018-11-6", # 時間 "theatre" : "Skyline", # 地點 "sold" : false, # 這個票是否已經賣出 "actors" : [ # 演員"Jo Hangum","Jon Hittle","Rob Kettleman","Laura Conrad","Simon Hower","Nora Blue"], "number" : 8, #可以使用的人數(團體座位) "datetime" : 1541497200000, "price" : 8321, # 票價 "tip" : 17.5, # 優惠 "time" : "5:40PM" }

    總共有3w條這樣的數據

    2. metric aggregation分類

    1 . Avg Aggregation : 求query出來的結果的average 值
    2 . Weighted Avg Aggregation: 帶權重的average值,可以選取另一個字段的值作為權重值
    3 . Max Aggregation: 求query出來的結果的max值
    4 . Min Aggregation: 求query出來的結果的min值
    5 . Sum Aggregation: 求query出來的結果的sum值
    6 . Value Count Aggregation: query出來的結果的某個field的的值的個數,注意可能這個field的值是一個數組則這個一個doc可能就貢獻了多個value count
    7 . Cardinality Aggregation: 某個filed的value去重后的count, 可以理解為value_count做了去重
    8 . Percentiles Aggregation: 百分比求值,對于大小的數值,求百分位,比如響應時間的99分位,95分位等對應的具體響應時間是多少
    9 . Percentile Ranks Aggregation: 某個具體的響應時間在總體中所處的分位值
    10. Stats Aggregation: 上面value_count,min,max,sum,avg的快捷方式
    11. Extended Stats Aggregation: 在stats的基礎上增加了平方和、方差、標準差、平均值加/減兩個標準差的區間
    12. Top Hits Aggregation: 一般是嵌套查詢,用在term查詢當中,返回每個bucket的topN
    13. Geo Bounds Aggregation: 地理位置的邊界聚合
    14. Geo Centroid Aggregation:
    15. Scripted Metric Aggregation: 使用script的聚合
    16. Median Absolute Deviation Aggregation: 平方差聚合

    metric agg可以用作bucket agg的子聚合查詢,但是metric agg 本身不能包含子查詢

    3.使用樣例

    1 . Avg Aggregation : 求query出來的結果的average 值

    GET seats1028/_search {"size": 0,"aggs": {"avg_price": {"avg": {"field": "price"}}} }返回{"took" : 8,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 10000,"relation" : "gte"},"max_score" : null,"hits" : [ ]},"aggregations" : {"avg_price" : {"value" : 4995.498812220319}} }

    2 . Weighted Avg Aggregation: 帶權重的average值,可以選取另一個字段的值作為權重值

    GET seats1028/_search {"size": 0,"aggs": {"avg_price": {"weighted_avg": {"value": {"field": "price"},"weight": {"field": "number"}}}} }返回 {"took" : 14,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 10000,"relation" : "gte"},"max_score" : null,"hits" : [ ]},"aggregations" : {"avg_price" : {"value" : 4981.713482182667}} }

    3 . Max Aggregation: 求query出來的結果的max值

    GET seats1028/_search {"size": 0,"aggs": {"max_price": {"max": {"field": "price"}}} } 返回{"took" : 1,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 10000,"relation" : "gte"},"max_score" : null,"hits" : [ ]},"aggregations" : {"max_price" : {"value" : 9999.0}} }

    4 . Min Aggregation: 求query出來的結果的min值

    GET seats1028/_search {"size": 0,"aggs": {"min_price": {"min": {"field": "price"}}} }返回{"took" : 0,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 10000,"relation" : "gte"},"max_score" : null,"hits" : [ ]},"aggregations" : {"min_price" : {"value" : 0.0}} }

    5 . Sum Aggregation: 求query出來的結果的sum值

    GET seats1028/_search {"size": 0,"aggs": {"sum_price": {"sum": {"field": "price"}}} }返回{"took" : 8,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 10000,"relation" : "gte"},"max_score" : null,"hits" : [ ]},"aggregations" : {"sum_price" : {"value" : 1.80847048E8}} }

    6 . Value Count Aggregation: query出來的結果的某個field的的值的個數,注意可能這個field的值是一個數組則這個一個doc可能就貢獻了多個value count

    GET seats1028/_search {"size": 0,"aggs": {"count_price": {"value_count": {"field": "price"}}} }返回 {"took" : 13,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 10000,"relation" : "gte"},"max_score" : null,"hits" : [ ]},"aggregations" : {"count_price" : {"value" : 36202}} }

    7 . Cardinality Aggregation: 某個filed的value去重后的count, 可以理解為value_count做了去重

    GET seats1028/_search {"size": 0,"aggs": {"unique_count_price": {"cardinality": {"field": "price"}}} }返回 {"took" : 13,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 10000,"relation" : "gte"},"max_score" : null,"hits" : [ ]},"aggregations" : {"unique_count_price" : {"value" : 9591}} }

    8 . Percentiles Aggregation: 百分比求值,對于大小的數值,求百分位,比如響應時間的99分位,95分位等對應的具體響應時間是多少

    GET seats1028/_search {"size": 0,"aggs": {"percentile_price": {"percentiles": {"field": "price"}}} }返回 {"took" : 56,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 10000,"relation" : "gte"},"max_score" : null,"hits" : [ ]},"aggregations" : {"percentile_price" : {"values" : {"1.0" : 100.22,"5.0" : 500.1716280451575,"25.0" : 2478.398741375389,"50.0" : 4990.070945393942,"75.0" : 7509.41570777247,"95.0" : 9487.07620155039,"99.0" : 9894.284278074867}}} }

    9 . Percentile Ranks Aggregation: 某個具體的響應時間在總體中所處的分位值

    GET seats1028/_search {"size": 0,"aggs": {"rank_price": {"percentile_ranks": {"field": "price","values": [1000,2500]}}} }返回 {"took" : 15,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 10000,"relation" : "gte"},"max_score" : null,"hits" : [ ]},"aggregations" : {"rank_price" : {"values" : {"1000.0" : 9.948376390210644,"2500.0" : 25.172259605722964}}} }

    10. Stats Aggregation: 上面value_count,min,max,sum,avg的快捷方式

    GET seats1028/_search {"size": 0,"aggs": {"stats_price": {"stats": {"field": "price"}}} }返回 {"took" : 9,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 10000,"relation" : "gte"},"max_score" : null,"hits" : [ ]},"aggregations" : {"stats_price" : {"count" : 36202,"min" : 0.0,"max" : 9999.0,"avg" : 4995.498812220319,"sum" : 1.80847048E8}} }

    11. top_hit

    這個一般用于嵌套的子查詢,比如下面的查詢按照row劃分bucket,然后找出每個bucket中的price最高的兩個

    GET seats1105/_search {"size": 1,"query": {"match_all": {}},"aggs": {"row_term": {"terms": {"field": "row","size": 10},"aggs": {"top_price": {"top_hits": {"size": 2,"sort": [{"price": {"order": "desc"}}]}}}}} }

    返回

    "aggregations" : {"row_term" : {"doc_count_error_upper_bound" : 0,"sum_other_doc_count" : 0,"buckets" : [{"key" : 2,"doc_count" : 5796,"top_price" : {"hits" : {"total" : {"value" : 5796,"relation" : "eq"},"max_score" : null,"hits" : [{"_index" : "seats1105","_type" : "_doc","_id" : "1957","_score" : null,"_source" : {"price" : 9998},"sort" : [9998]},{"_index" : "seats1105","_type" : "_doc","_id" : "7105","_score" : null,"_source" : {"price" : 9997},"sort" : [9997]}]}}},{"key" : 3,"doc_count" : 5796,"top_price" : {"hits" : {"total" : {"value" : 5796,"relation" : "eq"},"max_score" : null,"hits" : [{"_index" : "seats1105","_type" : "_doc","_id" : "3993","_score" : null,"_source" : {"price" : 9999},"sort" : [9999]},{"_index" : "seats1105","_type" : "_doc","_id" : "6656","_score" : null,"_source" : {"price" : 9999},"sort" : [9999]}]}}},{"key" : 1,"doc_count" : 5791,"top_price" : {"hits" : {"total" : {"value" : 5791,"relation" : "eq"},"max_score" : null,"hits" : [{"_index" : "seats1105","_type" : "_doc","_id" : "4321","_score" : null,"_source" : {"price" : 9999},"sort" : [9999]},{"_index" : "seats1105","_type" : "_doc","_id" : "8380","_score" : null,"_source" : {"price" : 9999},"sort" : [9999]}]}}}]}

    總結

    以上是生活随笔為你收集整理的01.elasticsearch metric aggregation 查询的全部內容,希望文章能夠幫你解決所遇到的問題。

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

    主站蜘蛛池模板: 欲涩漫入口免费网站 | 久久亚洲综合国产精品99麻豆精品福利 | 欧美性一区| 激情五月深爱五月 | 国产高清久久 | 炕上如狼似虎的呻吟声 | 蜜臀av午夜精品 | 国产精品天天狠天天看 | 久99视频| 日韩欧美一区二区三区视频 | 一区二区美女视频 | 成人免费无遮挡无码黄漫视频 | 插插插av | 91免费版在线 | 欧美性俱乐部 | 国产一区二区在线观看免费 | av播播| 911亚洲精选 | 精品久久久久中文慕人妻 | 亚洲天堂热 | 色戒av | 蜜桃av噜噜一区二区三区网址 | 国产操比视频 | 亚洲永久无码精品 | 成人在线观看小视频 | 少妇高潮喷水在线观看 | www色网站| 视频在线观看 | 另类在线视频 | av一区在线播放 | 麻豆福利在线观看 | 国产精品久久久久久久妇 | 狠狠操狠狠操 | 又骚又黄的视频 | 嫩草嫩草嫩草嫩草嫩草 | 天干夜天干天天天爽视频 | 黄色一级网 | 国产精品成人国产乱 | 国产寡妇色xxⅹ交肉视频 | 成年人高清视频 | 992tv在线影院| 日韩中文字幕一区二区三区 | 美国伊人网 | 久久午夜场 | 国产suv精品一区二区 | 欧美日韩国产第一页 | 天堂av一区二区三区 | 狠狠干b| 精品人妻无码一区二区三区 | 国产资源第一页 | 色xxxxx | 四虎毛片| 日韩精品视频一区二区三区 | 无码 制服 丝袜 国产 另类 | 丰满放荡岳乱妇91ww | 三级视频在线 | 成人在线观看免费高清 | 亚洲综合大片69999 | 最近日韩中文字幕中文 | 国产免费二区 | 一区二区蜜桃 | 人人爽人人干 | 亚洲综合网在线 | 免费毛片播放 | 国产熟妇一区二区三区四区 | 欧美日韩精品一区二区在线观看 | 国产在线视频第一页 | 天天爽夜夜爽夜夜爽精品 | 国产99热| 极品白嫩丰满美女无套 | 日韩在线欧美在线 | 亚洲黄色网页 | 豆花在线观看 | 日韩在线视频免费观看 | 91国偷自产一区二区三区女王 | 黄色一级免费片 | 欧美日韩在线视频一区二区 | 日本免费网址 | 青青青草视频 | 麻豆射区| 男女无套免费视频网站动漫 | 朝桐光av在线一区二区三区 | 狂野欧美性猛交xxxx巴西 | 99久久国产综合 | 人妻av无码一区二区三区 | 波多野结衣av无码 | bangbros性欧美18 | 狠狠噜噜 | 色导航在线 | 亚洲骚图| 超碰997 | 午夜成年人视频 | 久久亚洲一区 | 一区二区三区四区免费观看 | 黑鬼巨鞭白妞冒白浆 | 佐佐木明希电影 | 在线波多野结衣 | 日韩一卡二卡在线 | 午夜久久久久久久久久 |