Java Code Examples for org.elasticsearch.search.aggregations.metrics.sum.Sum#getValue()
The following examples show how to use
org.elasticsearch.search.aggregations.metrics.sum.Sum#getValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElasticsearchDataQuery.java From frostmourne with MIT License | 6 votes |
private Double findAggregationValue(MetricContract metricContract, SearchResponse searchResponse) { String aggType = metricContract.getAggregation_type(); if (aggType.equalsIgnoreCase("max")) { Max max = searchResponse.getAggregations().get("maxNumber"); return max.getValue(); } if (aggType.equalsIgnoreCase("min")) { Min min = searchResponse.getAggregations().get("minNumber"); return min.getValue(); } if (aggType.equalsIgnoreCase("avg")) { Avg avg = searchResponse.getAggregations().get("avgNumber"); return avg.getValue(); } if (aggType.equalsIgnoreCase("sum")) { Sum sum = searchResponse.getAggregations().get("sumNumber"); return sum.getValue(); } throw new IllegalArgumentException("unsupported aggregation type: " + aggType); }
Example 2
Source File: MetricsQueryEsDAO.java From skywalking with Apache License 2.0 | 5 votes |
@Override public int readMetricsValue(final MetricsCondition condition, final String valueColumnName, final Duration duration) throws IOException { SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource(); buildQuery(sourceBuilder, condition, duration); TermsAggregationBuilder entityIdAggregation = AggregationBuilders.terms(Metrics.ENTITY_ID) .field(Metrics.ENTITY_ID) .size(1); final Function function = ValueColumnMetadata.INSTANCE.getValueFunction(condition.getName()); functionAggregation(function, entityIdAggregation, valueColumnName); sourceBuilder.aggregation(entityIdAggregation); SearchResponse response = getClient().search(condition.getName(), sourceBuilder); Terms idTerms = response.getAggregations().get(Metrics.ENTITY_ID); for (Terms.Bucket idBucket : idTerms.getBuckets()) { switch (function) { case Sum: Sum sum = idBucket.getAggregations().get(valueColumnName); return (int) sum.getValue(); case Avg: Avg avg = idBucket.getAggregations().get(valueColumnName); return (int) avg.getValue(); default: avg = idBucket.getAggregations().get(valueColumnName); return (int) avg.getValue(); } } return ValueColumnMetadata.INSTANCE.getDefaultValue(condition.getName()); }