提交 9e208d04 编写于 作者: 彭勇升 pengys 提交者: wu-sheng

Fixed the bug of the getValues method in metric query. (#1739)

上级 1955e9d3
......@@ -31,6 +31,8 @@ import org.elasticsearch.action.get.*;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.*;
import org.elasticsearch.search.aggregations.metrics.avg.Avg;
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
import org.elasticsearch.search.builder.SearchSourceBuilder;
/**
......@@ -59,13 +61,22 @@ public class MetricQueryEsDAO extends EsDAO implements IMetricQueryDAO {
IntValues intValues = new IntValues();
Terms idTerms = response.getAggregations().get(Indicator.ENTITY_ID);
for (Terms.Bucket idBucket : idTerms.getBuckets()) {
Terms valueTerms = idBucket.getAggregations().get(valueCName);
for (Terms.Bucket valueBucket : valueTerms.getBuckets()) {
KVInt value = new KVInt();
value.setId(idBucket.getKeyAsString());
value.setValue(valueBucket.getKeyAsNumber().intValue());
intValues.getValues().add(value);
int value = 0;
switch (function) {
case Sum:
Sum sum = idBucket.getAggregations().get(valueCName);
value = (int)sum.getValue();
break;
case Avg:
Avg avg = idBucket.getAggregations().get(valueCName);
value = (int)avg.getValue();
break;
}
KVInt kvInt = new KVInt();
kvInt.setId(idBucket.getKeyAsString());
kvInt.setValue(value);
intValues.getValues().add(kvInt);
}
return intValues;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册