use of org.elasticsearch.search.aggregations.bucket.range.date.DateRangeBuilder in project vertigo by KleeGroup.
the class ESSearchRequestBuilder method dateRangeFacetToAggregationBuilder.
private static AggregationBuilder<DateRangeBuilder> dateRangeFacetToAggregationBuilder(final FacetDefinition facetDefinition, final DtField dtField) {
final DateRangeBuilder dateRangeBuilder = AggregationBuilders.dateRange(facetDefinition.getName()).field(dtField.getName()).format(DATE_PATTERN);
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 String minValue = parsedFilter[3];
final String maxValue = parsedFilter[4];
if ("*".equals(minValue)) {
dateRangeBuilder.addUnboundedTo(filterValue, maxValue);
} else if ("*".equals(maxValue)) {
dateRangeBuilder.addUnboundedFrom(filterValue, minValue);
} else {
// always min include and max exclude in ElasticSearch
dateRangeBuilder.addRange(filterValue, minValue, maxValue);
}
}
return dateRangeBuilder;
}
Aggregations