org.elasticsearch.search.aggregations.metrics.stats.Stats Java Examples
The following examples show how to use
org.elasticsearch.search.aggregations.metrics.stats.Stats.
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: AggregationResponseHandle.java From jetlinks-community with Apache License 2.0 | 6 votes |
private static <A extends Aggregation> void route(Bucket bucket, A a) { if (a instanceof Terms) { bucket.setBuckets(terms(a)); } else if (a instanceof Range) { bucket.setBuckets(range(a)); } else if (a instanceof Histogram) { bucket.setBuckets(range(a)); } else if (a instanceof Avg) { bucket.setAvg(avg(a)); } else if (a instanceof Min) { bucket.setMin(min(a)); } else if (a instanceof Max) { bucket.setMax(max(a)); } else if (a instanceof Sum) { bucket.setSum(sum(a)); } else if (a instanceof Stats) { stats(bucket, a); } else if (a instanceof ValueCount) { bucket.setValueCount(count(a)); } else { throw new UnsupportedOperationException("不支持的聚合类型"); } }
Example #2
Source File: AnalyticsServiceElasticsearch.java From hawkular-apm with Apache License 2.0 | 6 votes |
private static TimeseriesStatistics toTimeseriesStatistics(Bucket bucket) { Stats stat = bucket.getAggregations().get("stats"); long faultCount = bucket.getAggregations() .<Nested>get("nested").getAggregations() .<Filter>get("faults").getDocCount(); TimeseriesStatistics s = new TimeseriesStatistics(); s.setTimestamp(bucket.getKeyAsDate().getMillis()); s.setAverage((long)stat.getAvg()); s.setMin((long)stat.getMin()); s.setMax((long)stat.getMax()); s.setCount(stat.getCount()); s.setFaultCount(faultCount); return s; }
Example #3
Source File: AnalyticsServiceElasticsearch.java From hawkular-apm with Apache License 2.0 | 4 votes |
/** * This method builds a map of communication summary stats related to the supplied * criteria. * * @param stats The map of communication summary stats * @param index The index * @param criteria The criteria * @param addMetrics Whether to add metrics on the nodes/links */ private void buildCommunicationSummaryStatistics(Map<String, CommunicationSummaryStatistics> stats, String index, Criteria criteria, boolean addMetrics) { if (!refresh(index)) { return; } // Don't specify target class, so that query provided that can be used with // CommunicationDetails and CompletionTime BoolQueryBuilder query = buildQuery(criteria, ElasticsearchUtil.TRANSACTION_FIELD, null); // Only want external communications query = query.mustNot(QueryBuilders.matchQuery("internal", "true")); StatsBuilder latencyBuilder = AggregationBuilders .stats("latency") .field(ElasticsearchUtil.LATENCY_FIELD); TermsBuilder targetBuilder = AggregationBuilders .terms("target") .field(ElasticsearchUtil.TARGET_FIELD) .size(criteria.getMaxResponseSize()) .subAggregation(latencyBuilder); TermsBuilder sourceBuilder = AggregationBuilders .terms("source") .field(ElasticsearchUtil.SOURCE_FIELD) .size(criteria.getMaxResponseSize()) .subAggregation(targetBuilder); SearchRequestBuilder request = getBaseSearchRequestBuilder(COMMUNICATION_DETAILS_TYPE, index, criteria, query, 0) .addAggregation(sourceBuilder); SearchResponse response = getSearchResponse(request); for (Terms.Bucket sourceBucket : response.getAggregations().<Terms>get("source").getBuckets()) { Terms targets = sourceBucket.getAggregations().get("target"); CommunicationSummaryStatistics css = stats.get(sourceBucket.getKey()); if (css == null) { css = new CommunicationSummaryStatistics(); css.setId(sourceBucket.getKey()); css.setUri(EndpointUtil.decodeEndpointURI(css.getId())); css.setOperation(EndpointUtil.decodeEndpointOperation(css.getId(), true)); stats.put(css.getId(), css); } if (addMetrics) { css.setCount(sourceBucket.getDocCount()); } for (Terms.Bucket targetBucket : targets.getBuckets()) { Stats latency = targetBucket.getAggregations().get("latency"); String linkId = targetBucket.getKey(); ConnectionStatistics con = css.getOutbound().get(linkId); if (con == null) { con = new ConnectionStatistics(); css.getOutbound().put(linkId, con); } if (addMetrics) { con.setMinimumLatency((long)latency.getMin()); con.setAverageLatency((long)latency.getAvg()); con.setMaximumLatency((long)latency.getMax()); con.setCount(targetBucket.getDocCount()); } } } addNodeInformation(stats, index, criteria, addMetrics, false); addNodeInformation(stats, index, criteria, addMetrics, true); }
Example #4
Source File: AnalyticsServiceElasticsearch.java From hawkular-apm with Apache License 2.0 | 4 votes |
private void doAddMetrics(CommunicationSummaryStatistics css, Stats duration, long docCount) { css.setMinimumDuration((long)duration.getMin()); css.setAverageDuration((long)duration.getAvg()); css.setMaximumDuration((long)duration.getMax()); css.setCount(docCount); }