在弹性搜索中找到中值元素

时间:2017-12-22 22:59:02

标签: elasticsearch

我还想查找我的文档的中位年龄字段,并在线使用百分位功能找到了一个示例。

curl localhost:9200/residents/_search  -d '{"size": 0,
  "aggs" : {
     "percentile" : {
         "percentile" : {
             "field" : "age" ,
             "percents" : [50]}}}}'

但我收到错误

{
  "error" : {
    "root_cause" : [
      {
        "type" : "unknown_named_object_exception",
        "reason" : "Unknown BaseAggregationBuilder [percentile]",
        "line" : 6,
        "col" : 25
      }
    ],
    "type" : "unknown_named_object_exception",
    "reason" : "Unknown BaseAggregationBuilder [percentile]",
    "line" : 6,
    "col" : 25
  },
  "status" : 400
}

1 个答案:

答案 0 :(得分:0)

ElasticSearch中只有百分位数聚合。尝试使用

curl localhost:9200/residents/_search  -d '{"size": 0,
  "aggs" : {
     "percentile" : {
         "percentiles" : {
             "field" : "age" ,
             "percents" : [50]}}}}'