Search in sources :

Example 1 with RangeBuilder

use of org.elasticsearch.search.aggregations.bucket.range.RangeBuilder in project sonarqube by SonarSource.

the class ProjectMeasuresIndex method createRangeFacet.

private static AbstractAggregationBuilder createRangeFacet(String metricKey, Double... thresholds) {
    RangeBuilder rangeAgg = AggregationBuilders.range(metricKey).field(FIELD_MEASURES_VALUE);
    final int lastIndex = thresholds.length - 1;
    IntStream.range(0, thresholds.length).forEach(i -> {
        if (i == 0) {
            rangeAgg.addUnboundedTo(thresholds[0]);
            rangeAgg.addRange(thresholds[0], thresholds[1]);
        } else if (i == lastIndex) {
            rangeAgg.addUnboundedFrom(thresholds[lastIndex]);
        } else {
            rangeAgg.addRange(thresholds[i], thresholds[i + 1]);
        }
    });
    return AggregationBuilders.nested("nested_" + metricKey).path(FIELD_MEASURES).subAggregation(AggregationBuilders.filter("filter_" + metricKey).filter(termsQuery(FIELD_MEASURES_KEY, metricKey)).subAggregation(rangeAgg));
}
Also used : RangeBuilder(org.elasticsearch.search.aggregations.bucket.range.RangeBuilder)

Aggregations

RangeBuilder (org.elasticsearch.search.aggregations.bucket.range.RangeBuilder)1