ES求中位数

ES中没有像求平均值一样,可以直接获取中位数的方法,可以使用获取某个数值字段50%的值的方法来获取。

GET applog-xmllog-2021-04-08/_search?pretty
{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "system_code.keyword": "InterfPlus"
          }
        },
        {
          "term": {
            "method_cname.keyword": "查询航班(IBE+Shop)"
          }
        },
        {
          "range": {
            "created_time": {
              "lte": "now",
              "gte": "now-30m"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "percentiles": {
      "percentiles": {
        "field": "duration",
        "percents": [
          50
        ]
      }
    }
  }
}
原文地址:https://www.cnblogs.com/wugang/p/14632340.html