Search in sources :

Example 1 with LongBounds

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);
}
Also used : FilterAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) SumAggregationBuilder(org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder) TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) FilterAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) AggregationBuilder(org.elasticsearch.search.aggregations.AggregationBuilder) PeriodStart(org.sonar.server.issue.index.IssueQuery.PeriodStart) OptionalLong(java.util.OptionalLong) DateHistogramInterval(org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval) Duration(org.joda.time.Duration) Date(java.util.Date) LongBounds(org.elasticsearch.search.aggregations.bucket.histogram.LongBounds)

Aggregations

Date (java.util.Date)1 OptionalLong (java.util.OptionalLong)1 AggregationBuilder (org.elasticsearch.search.aggregations.AggregationBuilder)1 FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)1 DateHistogramInterval (org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval)1 LongBounds (org.elasticsearch.search.aggregations.bucket.histogram.LongBounds)1 TermsAggregationBuilder (org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder)1 SumAggregationBuilder (org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder)1 Duration (org.joda.time.Duration)1 PeriodStart (org.sonar.server.issue.index.IssueQuery.PeriodStart)1