Source:
public List<TransactionInfo> getTransactionInfo(String tenantId, Criteria criteria) { String index = client.getIndex(tenantId); if (!refresh(index)) { return null; } if (criteria.getBusinessTransaction() != null) { criteria = new Criteria(criteria); criteria.setBusinessTransaction(null); } TermsBuilder cardinalityBuilder = AggregationBuilders .terms("cardinality") .field("businessTransaction") .order(Order.aggregation("_count", false)) .size(criteria.getMaxResponseSize()); BoolQueryBuilder query = buildQuery(criteria, "startTime", "businessTransaction", Trace.class); SearchRequestBuilder request = getBaseSearchRequestBuilder(TRACE_TYPE, index, criteria, query, 0) .addAggregation(cardinalityBuilder); SearchResponse response = getSearchResponse(request); Terms terms = response.getAggregations().get("cardinality"); List<TransactionInfo> txnInfo = terms.getBuckets().stream() .map(AnalyticsServiceElasticsearch::toTransactionInfo) .sorted((one, another) -> one.getName().compareTo(another.getName())) .collect(Collectors.toList()); if (configService != null) { Map<String,BusinessTxnConfig> btcs = configService.getBusinessTransactions(tenantId, 0); txnInfo.forEach(ti -> { BusinessTxnConfig btc = btcs.get(ti.getName()); if (btc != null) { ti.setLevel(btc.getLevel()); ti.setStaticConfig(true); btcs.remove(ti.getName()); } }); btcs.forEach((k,v) -> txnInfo.add(new TransactionInfo().setName(k).setLevel(v.getLevel()).setStaticConfig(true))); Collections.sort(txnInfo, new Comparator<TransactionInfo>() { @Override public int compare(TransactionInfo arg0, TransactionInfo arg1) { return arg0.getName().compareTo(arg1.getName()); } }); } return txnInfo; }

Target:
public List<TransactionInfo> getTransactionInfo(String tenantId, Criteria criteria) { String index = client.getIndex(tenantId); if (!refresh(index)) { return null; } if (criteria.getBusinessTransaction() != null) { criteria = new Criteria(criteria); criteria.setBusinessTransaction(null); } TermsBuilder cardinalityBuilder = AggregationBuilders .terms("cardinality") .field("businessTransaction") .order(Order.aggregation("_count", false)) .size(criteria.getMaxResponseSize()); BoolQueryBuilder query = buildQuery(criteria, "startTime", "businessTransaction", Trace.class); SearchRequestBuilder request = getBaseSearchRequestBuilder(TRACE_TYPE, index, criteria, query, 0) .addAggregation(cardinalityBuilder); SearchResponse response = getSearchResponse(request); Terms terms = response.getAggregations().get("cardinality"); List<TransactionInfo> txnInfo = terms.getBuckets().stream() .map(AnalyticsServiceElasticsearch::toTransactionInfo) .collect(Collectors.toList()); if (configService != null) { Map<String,BusinessTxnConfig> btcs = configService.getBusinessTransactions(tenantId, 0); txnInfo.forEach(ti -> { BusinessTxnConfig btc = btcs.get(ti.getName()); if (btc != null) { ti.setLevel(btc.getLevel()); ti.setStaticConfig(true); btcs.remove(ti.getName()); } }); btcs.forEach((k,v) -> txnInfo.add(new TransactionInfo().setName(k).setLevel(v.getLevel()).setStaticConfig(true))); } Collections.sort(txnInfo, new Comparator<TransactionInfo>() { @Override public int compare(TransactionInfo ti1, TransactionInfo ti2) { return ti1.getName().compareTo(ti2.getName()); } }); return txnInfo; }