use of org.elasticsearch.search.aggregations.bucket.histogram.LongBounds in project sonarqube by SonarSource.
the class IssueIndex method getCreatedAtFacet.
private Optional<AggregationBuilder> getCreatedAtFacet(IssueQuery query, TopAggregationHelper aggregationHelper, AllFilters allFilters) {
long startTime;
boolean startInclusive;
PeriodStart createdAfter = query.createdAfter();
if (createdAfter == null) {
OptionalLong minDate = getMinCreatedAt(allFilters);
if (!minDate.isPresent()) {
return Optional.empty();
}
startTime = minDate.getAsLong();
startInclusive = true;
} else {
startTime = createdAfter.date().getTime();
startInclusive = createdAfter.inclusive();
}
Date createdBefore = query.createdBefore();
long endTime = createdBefore == null ? system.now() : createdBefore.getTime();
Duration timeSpan = new Duration(startTime, endTime);
DateHistogramInterval bucketSize = computeDateHistogramBucketSize(timeSpan);
FilterAggregationBuilder topAggregation = aggregationHelper.buildTopAggregation(CREATED_AT.getName(), CREATED_AT.getTopAggregationDef(), NO_EXTRA_FILTER, t -> {
AggregationBuilder dateHistogram = AggregationBuilders.dateHistogram(CREATED_AT.getName()).field(CREATED_AT.getFieldName()).dateHistogramInterval(bucketSize).minDocCount(0L).format(DateUtils.DATETIME_FORMAT).timeZone(Optional.ofNullable(query.timeZone()).orElse(system.getDefaultTimeZone().toZoneId())).extendedBounds(new LongBounds(startInclusive ? startTime : (startTime + 1), endTime - 1L));
addEffortAggregationIfNeeded(query, dateHistogram);
t.subAggregation(dateHistogram);
});
return Optional.of(topAggregation);
}
Aggregations