參考鏈接:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html
es 各個(gè)版本的語法可能會(huì)不一樣,如果大家在用的時(shí)候發(fā)現(xiàn)語法報(bào)錯(cuò)了,請(qǐng)查閱相關(guān)版本的語法。
剛需要按 ip 地址統(tǒng)計(jì)某個(gè)接口的訪問次數(shù),查了下 es 分組統(tǒng)計(jì)次數(shù) aggs 的用法,特此記錄一下,方便下次查閱。
GET filebeat-7.2.0-2021.01.07/doc/_search?size=0
{
"query": {
"bool": {
"must": [
{
"match": {
"uripath": "url"
}
}
]
}
},
"aggs": {
"my-agg-name": {
"terms": {
"field": "remote_addr"
}
}
}
}
my-agg-name 可以隨便命名,不改也行。
terms 、field 不需要改,需要改的是 remote_addr ,按實(shí)際的字段名稱修改即可。文章來源:http://www.zghlxwxcb.cn/news/detail-505186.html
返回結(jié)果:文章來源地址http://www.zghlxwxcb.cn/news/detail-505186.html
{
"took" : 1209,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 98605,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"my-agg-name" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 819,
"buckets" : [
{
"key" : "ip1",
"doc_count" : 42067
},
{
"key" : "ip2",
"doc_count" : 24665
},
{
"key" : "ip3",
"doc_count" : 24637
},
{
"key" : "ip4",
"doc_count" : 1703
},
{
"key" : "ip5",
"doc_count" : 1456
},
{
"key" : "ip6",
"doc_count" : 1438
},
{
"key" : "ip7",
"doc_count" : 561
},
{
"key" : "ip8",
"doc_count" : 496
},
{
"key" : "ip9",
"doc_count" : 445
},
{
"key" : "ip10",
"doc_count" : 318
}
]
}
}
}
到了這里,關(guān)于elastic search es 分組統(tǒng)計(jì) aggs 次數(shù)用法的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!