es聚合查詢


curl -XPOST "100.98.210.20:9200/logstash-2018.10.17/_search?pretty" -d '
{ "size" : 0,                            是否返回參考數據
"aggs": {         默認參數
"all_hostname": {     自定義返回名字
"terms":{         默認
"size":200,        查詢結果顯示多少條
"field":"hostname"                 聚合項
}
}
}
}'

源數據

{
    "took":1505,
    "timed_out":false,
    "_shards":{
        "total":20,
        "successful":20,
        "failed":0
    },
    "hits":{
        "total":114409200,
        "max_score":1,
        "hits":[
            {
                "_index":"logstash-2018.10.16",
                "_type":"ngix_13_log",
                "_id":"AWZ6OpP8XYOz2dgYz_lS",
                "_score":1,
                "_source":{
                    "timestamp":"2018-10-16T08:15:50+08:00",
                    "remoteAddr":"100.117.117.38",
                    "forwardedip":"180.130.2.234, 118.178.15.252",
                    "status":"200",
                    "hostname":"apstuent2c.com",
                    "uri":"/app_2c/discoveryv3/findCourseTopicList",
                    "server_port":"80",
                    "request":"POST /app_2c/discoveryv3/findCourseTopicList HTTP/1.1",
                    "requestUri":"/app_2c/discoveryv3/findCourseTopicList",
                    "request_time":0.008,
                    "http_referer":"-",
                    "http_user_agent":"okhttp/3.9.0",
                    "body_bytes_sent":417,
                    "upstream_http_host":"10.26.97.5:80",
                    "upstream_response_time":"0.006",
                    "@version":"1",
                    "@timestamp":"2018-10-16T00:15:51.083Z",
                    "path":"/usr/local/nginx/logs/acess_appsdent2c.log",
                    "type":"nginx_153_log",
                    "kafka":{
                        "msg_size":680,
                        "topic":"rizhi_nginx",
                        "consumer_group":"logstash_el",
                        "partition":6,
                        "offset":6047185082,
                        "key":null
                    }
                }
            },

返回結果:

"aggregations" : {
"all_hostname" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 614,
"buckets" : [ {
"key" : "apstdet2c.zhiushu.com",
"doc_count" : 63315744
}, {
"key" : "appsdent.zihishu.com",
"doc_count" : 48502113
}, {
"key" : "stdy.zhiuihu.com",
"doc_count" : 28878648
}, {


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM