PercentileAggregation - 转换为 HashMap

PercentileAggregation - Convert into HashMap

我在我的代码中使用 PercentileAggregation。 来自 _plugin/head 的结果:

"aggregations": {
"load_time_outlier": {
"values": {
"1.0": 35,
"1.0_as_string": "35.0",
"5.0": 35,
"5.0_as_string": "35.0",
"25.0": 35,
"25.0_as_string": "35.0",
"50.0": 35,
"50.0_as_string": "35.0",
"75.0": 35,
"75.0_as_string": "35.0",
"95.0": 36,
"95.0_as_string": "36.0",
"99.0": 36,
"99.0_as_string": "36.0"
}
}
}

通过 Java 客户端 (TCP),我得到的是 InternalPercentiles

    Aggregations aggregations = response.getAggregations();
    if(aggregations.getAsMap().get(aggregationKey) instanceof InternalPercentiles){
    InternalPercentiles intPercentiles = 
      (InternalPercentiles) aggregations.getAsMap().get(aggregationKey);
//My logic here
}   

我想在注释的地方写一个逻辑,这样我就可以得到我的地图结果:
键: load_time_outlier
值: 包含 [{"1.0": 35}, { "5.0": 35}, 等的地图的列表]

我试过的逻辑:

Iterator<Percentile> iterator = intPercentiles.iterator();
Map<String, Object> aggregationTermsMap = new LinkedHashMap<String, Object>();
while(iterator.hasNext()){
    Percentile percentile = iterator.next();
    aggregationTermsMap.put(new Double(percentile.getPercent()).toString(), percentile.getValue());
}
aggregationTermsList.add(aggregationTermsMap);
aggregationResults.put(aggregationKey, aggregationTermsList);

请输入。

得到答案:Class cast ((InternalPercentiles)intPercentiles).iterator() 丢失。

Iterator<Percentile> iterator = ((InternalPercentiles)intPercentiles).iterator();
Map<String, Object> aggregationTermsMap = new LinkedHashMap<String, Object>();
while(iterator.hasNext()){
    Percentile percentile = iterator.next();
    aggregationTermsMap.put(new Double(percentile.getPercent()).toString(), percentile.getValue());
}
aggregationTermsList.add(aggregationTermsMap);
aggregationResults.put(aggregationKey, aggregationTermsList);