GroupResult groupResult = new GroupResult(); groupResult.setKey(pivotField.getValue().toString()); groupResult.setTotal(pivotField.getCount()); Optional<String> scoreField = groupRequest.getScoreField(); if (scoreField.isPresent()) {
private List<GroupResult> getGroupResults(GroupRequest groupRequest, int index, Aggregations aggregations, Map<String, FieldType> commonColumnMetadata) { List<Group> groups = groupRequest.getGroups(); String field = groups.get(index).getField(); List<GroupResult> searchResultGroups = new ArrayList<>(); if(aggregations != null) { Terms terms = aggregations.get(getGroupByAggregationName(field)); for (Bucket bucket : terms.getBuckets()) { GroupResult groupResult = new GroupResult(); groupResult.setKey(formatKey(bucket.getKey(), commonColumnMetadata.get(field))); groupResult.setTotal(bucket.getDocCount()); Optional<String> scoreField = groupRequest.getScoreField(); if (scoreField.isPresent()) { Sum score = bucket.getAggregations().get(getSumAggregationName(scoreField.get())); groupResult.setScore(score.getValue()); } if (index < groups.size() - 1) { groupResult.setGroupedBy(groups.get(index + 1).getField()); groupResult.setGroupResults(getGroupResults(groupRequest, index + 1, bucket.getAggregations(), commonColumnMetadata)); } searchResultGroups.add(groupResult); } } return searchResultGroups; } }
private List<GroupResult> getGroupResults(List<Group> groups, int index) { Group group = groups.get(index); GroupResult groupResult = new GroupResult(); groupResult.setKey(group.getField() + "_value"); if (index < groups.size() - 1) { groupResult.setGroupedBy(groups.get(index + 1).getField()); groupResult.setGroupResults(getGroupResults(groups, index + 1)); } else { groupResult.setScore(50.0); } groupResult.setTotal(10); return Collections.singletonList(groupResult); }