我在代码中使用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);
请输入。
答案 0 :(得分:0)
得到了答案: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);