2017-03-15 136 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" 
    } 
    } 
    } 
    } 
} 
}