2017-03-15 145 views
0

如何使用弹性搜索计算另一个字段分组的一个字段的百分位数?我曾经尝试这样做:计算群体的百分位数?

GET /dealergeo/sale/_search 
{ 
    "size": 0, 
    "aggs": { 
    "dom_rank": { 
     "percentiles": { 
     "field": "avgdom" 
     }, 
     "aggs": { 
     "name": { 
      "terms": { 
      "field": "make", 
      "size": 10 
      } 
     } 
     } 
    } 
    } 
} 

所以基本上我想组由所有数据做然后计算avgdom的百分位数,但它给出了一个错误:

{ "error": { "root_cause": [ { "type": "aggregation_initialization_exception", "reason": "Aggregator [dom_rank] of type [percentiles] cannot accept sub-aggregations" } ], "type": "aggregation_initialization_exception", "reason": "Aggregator [dom_rank] of type [percentiles] cannot accept sub-aggregations" }, "status": 500 }

我是什么在这里失踪?或者这可能与弹性搜索?谢谢你的帮助!

回答

0

就想通了,我需要包装的terms聚集,而不是周围的其他方法里面的percentile聚集:

GET /dealergeo/sale/_search 
{ 
    "size": 0, 
    "aggs": { 
    "make_agg": { 
     "terms": { 
     "field": "make", 
     "size": 5 
    }, 
    "aggs": { 
     "dom_rank": { 
     "percentiles": { 
      "field": "avgdom" 
    } 
    } 
    } 
    } 
} 
}