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
        ]
      }
    }
  }
}
posted @ 2021-04-08 15:03  划破黑夜  阅读(745)  评论(0编辑  收藏  举报