ES7.16.2基础操作之percentiles百分比请求时长(十七)

## 初始化数据 
POST websit/logs/_bulk
 {"index":{}}
 {"latency":105,"province":"湖南","timestamp":"2021-10-28"}
 {"index":{}}
 {"latency":60,"province":"广东","timestamp":"2021-12-28"}
 {"index":{}}
 {"latency":70,"province":"广西","timestamp":"2021-10-28"}
 {"index":{}}
 {"latency":85,"province":"湖北","timestamp":"2022-01-01"}
 {"index":{}}
 {"latency":90,"province":"四川","timestamp":"2022-01-01"}
 {"index":{}}
 {"latency":100,"province":"湖南","timestamp":"2022-01-01"}
 {"index":{}}
 {"latency":65,"province":"江苏","timestamp":"2022-01-01"}
 {"index":{}}
 {"latency":75,"province":"广东","timestamp":"2021-10-28"}
 {"index":{}}
 {"latency":80,"province":"*","timestamp":"2021-12-31"}
 {"index":{}}
 {"latency":50,"province":"湖南","timestamp":"2021-07-31"}
 
## percentiles百分比统计
##tp50:50%的请求耗时最长在多长时间
##tp90:90%的请求耗时最长在多长时间
##tp95:95%的请求耗时最长在多长时间
GET websit/_search
{
  "size": 0,
  "aggs": {
    "latency_percentiles": {
      "percentiles": {
        "field": "latency",
        "percents": [
          50,
          90,
          95
        ]
      }
    },
    "latency_avg": {
      "avg": {
        "field": "latency"
      }
    }
  }
}

## 百分比统计:按省份分别统计请求时长
GET websit/_search
{
  "size": 0,
  "aggs": {
    "group_by_province": {
      "terms": {
        "field": "province.keyword"
      },
      "aggs": {
        "latency_percentiles": {
          "percentiles": {
            "field": "latency",
            "percents": [
              50,
              90,
              95
            ]
          }
        },
        "latency_avg": {
          "avg": {
            "field": "latency"
          }
        }
      }
    }
  }
}

上一篇:微信公众号开发(1)


下一篇:C# 唯一性ID生成器