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 ) ; }
This method builds a map of communication summary stats related to the supplied criteria .