use of org.elasticsearch.search.aggregations.bucket.histogram.ParsedHistogram in project vind by RBMHTechnology.
the class ResultUtils method getRangeFacetResults.
private static Pair<String, RangeFacetResult<?>> getRangeFacetResults(Aggregation aggregation, Facet rangeFacet) {
switch(rangeFacet.getType()) {
case "NumericRangeFacet":
final Facet.NumericRangeFacet numericRangeFacet = (Facet.NumericRangeFacet) rangeFacet;
final List<FacetValue> numericValues = new ArrayList<>();
Optional.ofNullable(aggregation).ifPresent(agg -> ((ParsedHistogram) ((ParsedRange) agg).getBuckets().get(0).getAggregations().getAsMap().get(rangeFacet.getFacetName())).getBuckets().stream().map(rangeBucket -> new FacetValue(DocumentUtil.castForDescriptor(rangeBucket.getKey(), numericRangeFacet.getFieldDescriptor(), FieldDescriptor.UseCase.Facet), rangeBucket.getDocCount())).forEach(numericValues::add));
return Pair.of(rangeFacet.getFacetName(), new RangeFacetResult(numericValues, numericRangeFacet.getStart(), numericRangeFacet.getEnd(), numericRangeFacet.getGap().longValue()));
default:
final Facet.DateRangeFacet dateRangeFacet = (Facet.DateRangeFacet) rangeFacet;
final List<FacetValue> dateValues = new ArrayList<>();
Optional.ofNullable(aggregation).ifPresent(agg -> ((ParsedDateHistogram) ((ParsedDateRange) agg).getBuckets().get(0).getAggregations().getAsMap().get(dateRangeFacet.getFacetName())).getBuckets().stream().map(rangeBucket -> new FacetValue(DocumentUtil.castForDescriptor(rangeBucket.getKey(), dateRangeFacet.getFieldDescriptor(), FieldDescriptor.UseCase.Facet), rangeBucket.getDocCount())).forEach(dateValues::add));
return Pair.of(rangeFacet.getFacetName(), new RangeFacetResult(dateValues, dateRangeFacet.getStart(), dateRangeFacet.getEnd(), dateRangeFacet.getGap().longValue()));
}
}
Aggregations