ES 學習8 聚合1

2022-05-17 23:26:30 字數 1200 閱讀 9314

特定概念:

桶(buckets)

滿足特定條件的文件的集合

指標(metrics)

對桶內的文件進行統計計算

select count(color) 

from table

group by color

count(color)相當於指標。

group by color相當於桶。

聚合例子:

curl -xget '

localhost:9200/text/_search?pretty

' -d '}}

}'

對port欄位做聚合,結果名稱為popular_ports。size設為0表示不關心搜尋結果,結果的hits部分會是空值。

計算每種顏色車輛**的平均值

get /cars/transactions/_search

,

"aggs": }}

}}

}

巢狀桶每個顏色的汽車製造商的分布

get /cars/transactions/_search

,

"aggs":

},"make": }}

}}

}

每個顏色的汽車製造商的分布,以及各個製造商生產汽車的最高和最低**。

get /cars/transactions/_search

,

"aggs":

},"make

": ,

"aggs

": },

"max_price

" : } }}

}}

}}

條形圖histogram

get /cars/transactions/_search

,

"aggs":}}

}}

}

terms桶  extended_stats度量

get /cars/transactions/_search

,

"aggs": }}

}}}

ES 學習8 聚合1

參考資料 特定概念 桶 buckets 滿足特定條件的文件的集合 指標 metrics 對桶內的文件進行統計計算 select count color from table group by color count color 相當於指標。group by color相當於桶。聚合例子 curl x...

ES 學習9 聚合2

按時間統計 date histogram get cars transactions search 注意,這種寫法在數字字段沒有問題,但是在文字字段使用之前必須先把對應欄位的fielddata設為true才可以。否則會報錯 caused by 注意,設定了fielddata會消耗大量記憶體。返回空b...

ES聚合查詢例項

disable coord false adjust pure negative true boost 1 explain false,aggregations view code disable coord false adjust pure negative true boost 1 expla...