Search in sources :

Example 1 with ParsedHistogram

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()));
    }
}
Also used : RangeFacetResult(com.rbmhtechnology.vind.api.result.facet.RangeFacetResult) FacetValue(com.rbmhtechnology.vind.api.result.facet.FacetValue) ParsedHistogram(org.elasticsearch.search.aggregations.bucket.histogram.ParsedHistogram) ParsedDateHistogram(org.elasticsearch.search.aggregations.bucket.histogram.ParsedDateHistogram) ArrayList(java.util.ArrayList) Facet(com.rbmhtechnology.vind.api.query.facet.Facet)

Aggregations

Facet (com.rbmhtechnology.vind.api.query.facet.Facet)1 FacetValue (com.rbmhtechnology.vind.api.result.facet.FacetValue)1 RangeFacetResult (com.rbmhtechnology.vind.api.result.facet.RangeFacetResult)1 ArrayList (java.util.ArrayList)1 ParsedDateHistogram (org.elasticsearch.search.aggregations.bucket.histogram.ParsedDateHistogram)1 ParsedHistogram (org.elasticsearch.search.aggregations.bucket.histogram.ParsedHistogram)1