当前位置:网站首页>ES-aggregation聚合分析
ES-aggregation聚合分析
2022-04-23 09:34:00 【ALONG20】
集合的分类
Bucket Aggregation
一些列满足特定条件的文档集。
Metric Aggregation
一些数学运算,可以对文档字段进行统计分析。
Metric会基于数据集计算结果,除了支持在字段上进行计算,同样也支持在脚步(painless script)产生的结果之上进行计算。
大多数Metric是数学计算,仅输出一个值。
min / max / sum / avg / cardinality
部分Metric支持输出多个数值。
stats / percentiles /percentile_ranks
实战:查询航班目的地/出发地的统计信息、机票平均价、最贵机票价、最便宜机票价
get kibana_sample_data_flights/_mappings
# 输出
{
"kibana_sample_data_flights" : {
"mappings" : {
"properties" : {
"AvgTicketPrice" : {
"type" : "float"
},
"Cancelled" : {
"type" : "boolean"
},
"Carrier" : {
"type" : "keyword"
},
"Dest" : {
"type" : "keyword"
},
"DestAirportID" : {
"type" : "keyword"
},
"DestCityName" : {
"type" : "keyword"
},
"DestCountry" : {
"type" : "keyword"
},
"DestLocation" : {
"type" : "geo_point"
},
"DestRegion" : {
"type" : "keyword"
},
"DestWeather" : {
"type" : "keyword"
},
"DistanceKilometers" : {
"type" : "float"
},
"DistanceMiles" : {
"type" : "float"
},
"FlightDelay" : {
"type" : "boolean"
},
"FlightDelayMin" : {
"type" : "integer"
},
"FlightDelayType" : {
"type" : "keyword"
},
"FlightNum" : {
"type" : "keyword"
},
"FlightTimeHour" : {
"type" : "keyword"
},
"FlightTimeMin" : {
"type" : "float"
},
"Origin" : {
"type" : "keyword"
},
"OriginAirportID" : {
"type" : "keyword"
},
"OriginCityName" : {
"type" : "keyword"
},
"OriginCountry" : {
"type" : "keyword"
},
"OriginLocation" : {
"type" : "geo_point"
},
"OriginRegion" : {
"type" : "keyword"
},
"OriginWeather" : {
"type" : "keyword"
},
"dayOfWeek" : {
"type" : "integer"
},
"timestamp" : {
"type" : "date"
}
}
}
}
}
get kibana_sample_data_flights/_search
{
"size":0,
"aggs":{
"flight_dest":{
//类似 select DestCountry count(*) from x group by DestCountry
"terms":{
"field": "DestCountry"
},
//aggs 开启统计
"aggs": {
// average_price 存储统计结果名称
"average_price": {
//avg 为统计函数
"avg": {
//根据AvgTicketPrice字段进行统计
"field": "AvgTicketPrice"
}
},
"max_price":{
"max": {
"field": "AvgTicketPrice"
}
},
"min_price":{
"min": {
"field": "AvgTicketPrice"
}
},
"stat_price":{
//stats 包含min/max/avg/sum统计
"stats": {
"field": "AvgTicketPrice"
}
},
"weather":{
"terms": {
"field": "DestWeather"
}
}
}
}
}
}
结果输出:
{
"took" : 18,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 10000,
"relation" : "gte"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"flight_dest" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 3187,
"buckets" : [
{
"key" : "IT",
"doc_count" : 2371,
"max_price" : {
"value" : 1195.3363037109375
},
"min_price" : {
"value" : 100.57646942138672
},
"weather" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "Clear",
"doc_count" : 428
},
{
"key" : "Sunny",
"doc_count" : 424
},
{
"key" : "Rain",
"doc_count" : 417
},
{
"key" : "Cloudy",
"doc_count" : 414
},
{
"key" : "Heavy Fog",
"doc_count" : 182
},
{
"key" : "Damaging Wind",
"doc_count" : 173
},
{
"key" : "Hail",
"doc_count" : 169
},
{
"key" : "Thunder & Lightning",
"doc_count" : 164
}
]
},
"average_price" : {
"value" : 586.9627099618385
},
"stat_price" : {
"count" : 2371,
"min" : 100.57646942138672,
"max" : 1195.3363037109375,
"avg" : 586.9627099618385,
"sum" : 1391688.585319519
}
}
]
}
}
}
Pipeline Aggregation
对其他的聚合结果进行二次聚合。
Matrix Aggregation
支持对多个字段的操作并提供一个结果矩阵。
版权声明
本文为[ALONG20]所创,转载请带上原文链接,感谢
https://blog.csdn.net/NF_ALONG/article/details/124308932
边栏推荐
- Vivo, hardware safe love and thunder
- How to protect open source projects from supply chain attacks - Security Design (1)
- Two methods of building Yum source warehouse locally
- 653. Sum of two IV - input BST
- [C language] document operation
- Yyds dry goods inventory ubuntu18 0.4 install MySQL and solve error 1698: access denied for user ''root' '@' 'localhost' '
- NLLLoss+log_ SoftMax=CE_ Loss
- kernel-pwn学习(4)--Double Fetch&&0CTF2018-baby
- STM32 and FreeRTOS stack parsing
- Redis exception read error on connection solution
猜你喜欢
Secrets in buffctf file 1
Kettle experiment
个人主页软件Fenrus
[geek challenge 2019] havefun1
Buuctf [actf2020 freshman competition] include1
Installation of data cleaning ETL tool kettle
nn. Explanation of module class
kettle实验
Personal homepage software fenrus
Go language learning notes - structure | go language from scratch
随机推荐
Yyds dry goods inventory ubuntu18 0.4 install MySQL and solve error 1698: access denied for user ''root' '@' 'localhost' '
[C language] document operation
AQS & reentrantlock implementation principle
Enter "net start MySQL" and "system error 5. Access denied" appears. Detailed explanation of the problem
Leetcode-199 - right view of binary tree
#yyds干货盘点#ubuntu18.0.4安装mysql并解决ERROR 1698: Access denied for user ''root''@''localhost''
SAP 03-amdp CDs table function using 'with' clause
高薪程序员&面试题精讲系列91之Limit 20000加载很慢怎么解决?如何定位慢SQL?
Group Backpack
DVWA range practice record
Kettle experiment
npm ERR! network
Flutter's loading animation is more interesting
Comparison of overloading, rewriting and hiding
GoLand debug go use - white record
112. 路径总和
JS case to find the maximum value, reverse the array, bubble sort
Random neurons and random depth of dropout Technology
亚马逊云科技入门资源中心,从0到1轻松上云
RSA encryption and decryption signature verification