use of org.elasticsearch.search.aggregations.metrics.ParsedSingleValueNumericMetricsAggregation in project vind by RBMHTechnology.
the class ResultUtils method getPivotFacetResults.
private static Pair<String, List<PivotFacetResult>> getPivotFacetResults(Aggregation aggregation, Facet.PivotFacet pivotFacet, Map<String, Facet> vindFacets) {
final FieldDescriptor field = pivotFacet.getFieldDescriptors().get(0);
if (Objects.nonNull(aggregation)) {
final ParsedTerms rootPivot = (ParsedTerms) aggregation;
final List<PivotFacetResult> pivotFacetResult = rootPivot.getBuckets().stream().map(bucket -> {
final Map<String, Aggregation> aggMap = bucket.getAggregations().asMap();
final Aggregation pivotAgg = aggMap.get(pivotFacet.getFacetName());
final Map<String, RangeFacetResult<?>> rangeSubfacets = new HashMap<>();
final Map<String, QueryFacetResult<?>> querySubfacets = new HashMap<>();
final Map<String, StatsFacetResult<?>> statsSubfacets = new HashMap<>();
Double score = null;
if (!pivotFacet.getSortings().isEmpty()) {
score = pivotFacet.getSortings().keySet().stream().map(aggMap::get).mapToDouble(sortAgg -> ((ParsedSingleValueNumericMetricsAggregation) sortAgg).value()).sum();
}
aggMap.values().forEach(agg -> {
if (ParsedExtendedStats.class.isAssignableFrom(agg.getClass())) {
final HashMap<String, Aggregation> statsMap = new HashMap<>();
statsMap.put(agg.getName(), agg);
statsSubfacets.put(agg.getName(), ResultUtils.getStatsFacetResults(statsMap, (Facet.StatsFacet) vindFacets.get(agg.getName())).getValue());
}
if (ParsedQuery.class.isAssignableFrom(agg.getClass())) {
querySubfacets.put(agg.getName(), ResultUtils.getQueryFacetResults(agg, (Facet.QueryFacet) vindFacets.get(agg.getName())).getValue());
}
if (ParsedRange.class.isAssignableFrom(agg.getClass())) {
rangeSubfacets.put(agg.getName(), ResultUtils.getRangeFacetResults(agg, vindFacets.get(agg.getName())).getValue());
}
});
final List<PivotFacetResult> subPivot = getPivotFacetResults(pivotAgg, pivotFacet, vindFacets).getValue();
return new PivotFacetResult(subPivot, bucket.getKey(), field, Long.valueOf(bucket.getDocCount()).intValue(), rangeSubfacets, querySubfacets, statsSubfacets, score);
}).collect(Collectors.toList());
return Pair.of(pivotFacet.getFacetName(), pivotFacetResult);
}
return Pair.of(null, null);
}
Aggregations