use of org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder in project vertigo by KleeGroup.
the class ESSearchRequestBuilder method numberRangeFacetToAggregationBuilder.
private static AggregationBuilder numberRangeFacetToAggregationBuilder(final FacetDefinition facetDefinition, final DtField dtField) {
final RangeAggregationBuilder rangeBuilder = //
AggregationBuilders.range(facetDefinition.getName()).field(dtField.getName());
for (final FacetValue facetRange : facetDefinition.getFacetRanges()) {
final String filterValue = facetRange.getListFilter().getFilterValue();
Assertion.checkState(filterValue.contains(dtField.getName()), "RangeFilter query ({1}) should use defined fieldName {0}", dtField.getName(), filterValue);
final String[] parsedFilter = DtListPatternFilterUtil.parseFilter(filterValue, RANGE_PATTERN).get();
final Optional<Double> minValue = convertToDouble(parsedFilter[3]);
final Optional<Double> maxValue = convertToDouble(parsedFilter[4]);
if (!minValue.isPresent()) {
rangeBuilder.addUnboundedTo(filterValue, maxValue.get());
} else if (!maxValue.isPresent()) {
rangeBuilder.addUnboundedFrom(filterValue, minValue.get());
} else {
// always min include and max exclude in ElasticSearch
rangeBuilder.addRange(filterValue, minValue.get(), maxValue.get());
}
}
return rangeBuilder;
}
Aggregations