多桶型聚合
1.词条聚合--terms
2.范围聚合--range
3,直方图聚合--histogram/日期直方图
4.嵌套聚合
5.地理距离聚合
include(包含)exclude(不包含)
bash
GET /get-together/_search?pretty
{
"size": 0,
"aggs": {
"tags": {
"terms": {
"field": "tags.verbatim",
"include": ".*search.*"
}
}
}
}
range范围聚合统计
bash
GET /get-together/_search
{
"aggs": {
"attendees_breakdown": {
"range": {
"script": {
"source": "doc['attendees'].size()"
},
"ranges": [
{"to": 4},
{"from": 4,"to": 6},
{"from": 6}
]
}
}
}
}
histogram定义一个固定间距,es会自动构建范围.
bash
#ES会构建从最小值开始的范围,并不断加入interval,
#直到包含最大值
GET /get-together/_search
{
"aggs": {
"attendees_histogram": {
"histogram": {
"script": {
"source": "doc['attendees'].size()"
},
"interval": 1
}
}
}
}
通过嵌套聚合获得结果分组