use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.AggregationBuilder in project sonarqube by SonarSource.
the class IssueIndex method addEffortTopAggregation.
private static void addEffortTopAggregation(TopAggregationHelper aggregationHelper, SearchSourceBuilder esRequest) {
AggregationBuilder topAggregation = aggregationHelper.buildTopAggregation(FACET_MODE_EFFORT, EFFORT_TOP_AGGREGATION, NO_EXTRA_FILTER, t -> t.subAggregation(EFFORT_AGGREGATION));
esRequest.aggregation(topAggregation);
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.AggregationBuilder in project sonarqube by SonarSource.
the class StickyFacetBuilder method buildTopFacetAggregation.
private FilterAggregationBuilder buildTopFacetAggregation(String fieldName, String facetName, BoolQueryBuilder facetFilter, int size, Function<TermsAggregationBuilder, AggregationBuilder> additionalAggregationFilter) {
TermsAggregationBuilder termsAggregation = buildTermsFacetAggregation(fieldName, facetName, size);
AggregationBuilder improvedAggregation = additionalAggregationFilter.apply(termsAggregation);
return AggregationBuilders.filter(facetName + "_filter", facetFilter).subAggregation(improvedAggregation);
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.AggregationBuilder in project sonarqube by SonarSource.
the class IssueIndex method addResolutionFacetIfNeeded.
private static void addResolutionFacetIfNeeded(SearchOptions options, IssueQuery query, TopAggregationHelper aggregationHelper, SearchSourceBuilder esRequest) {
if (!options.getFacets().contains(PARAM_RESOLUTIONS)) {
return;
}
AggregationBuilder aggregation = aggregationHelper.buildTermTopAggregation(RESOLUTIONS.getName(), RESOLUTIONS.getTopAggregationDef(), RESOLUTIONS.getNumberOfTerms(), NO_EXTRA_FILTER, t -> t.subAggregation(addEffortAggregationIfNeeded(query, AggregationBuilders.missing(RESOLUTIONS.getName() + FACET_SUFFIX_MISSING).field(RESOLUTIONS.getFieldName()))));
esRequest.aggregation(aggregation);
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.AggregationBuilder in project sonarqube by SonarSource.
the class IssueIndex method addAssigneesFacetIfNeeded.
private static void addAssigneesFacetIfNeeded(SearchOptions options, IssueQuery query, TopAggregationHelper aggregationHelper, SearchSourceBuilder esRequest) {
if (!options.getFacets().contains(PARAM_ASSIGNEES)) {
return;
}
Consumer<FilterAggregationBuilder> assigneeAggregations = t -> {
// optional second aggregation to return the issue count for selected assignees (if any)
Object[] assignees = query.assignees().toArray();
aggregationHelper.getSubAggregationHelper().buildSelectedItemsAggregation(ASSIGNEES.getName(), ASSIGNEES.getTopAggregationDef(), assignees).ifPresent(t::subAggregation);
// third aggregation to always return the count of unassigned in the assignee facet
t.subAggregation(addEffortAggregationIfNeeded(query, AggregationBuilders.missing(ASSIGNEES.getName() + FACET_SUFFIX_MISSING).field(ASSIGNEES.getFieldName())));
};
AggregationBuilder aggregation = aggregationHelper.buildTermTopAggregation(ASSIGNEES.getName(), ASSIGNEES.getTopAggregationDef(), ASSIGNEES.getNumberOfTerms(), NO_EXTRA_FILTER, assigneeAggregations);
esRequest.aggregation(aggregation);
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.AggregationBuilder in project sonarqube by SonarSource.
the class IssueIndex method getCreatedAtFacet.
private Optional<AggregationBuilder> getCreatedAtFacet(IssueQuery query, Map<String, QueryBuilder> filters, QueryBuilder esQuery) {
long startTime;
Date createdAfter = query.createdAfter();
if (createdAfter == null) {
Optional<Long> minDate = getMinCreatedAt(filters, esQuery);
if (!minDate.isPresent()) {
return Optional.empty();
}
startTime = minDate.get();
} else {
startTime = createdAfter.getTime();
}
Date createdBefore = query.createdBefore();
long endTime = createdBefore == null ? system.now() : createdBefore.getTime();
Duration timeSpan = new Duration(startTime, endTime);
DateHistogramInterval bucketSize = DateHistogramInterval.YEAR;
if (timeSpan.isShorterThan(TWENTY_DAYS)) {
bucketSize = DateHistogramInterval.DAY;
} else if (timeSpan.isShorterThan(TWENTY_WEEKS)) {
bucketSize = DateHistogramInterval.WEEK;
} else if (timeSpan.isShorterThan(TWENTY_MONTHS)) {
bucketSize = DateHistogramInterval.MONTH;
}
// from GMT to server TZ
int offsetInSeconds = -system.getDefaultTimeZone().getRawOffset() / 1_000;
AggregationBuilder dateHistogram = AggregationBuilders.dateHistogram(PARAM_CREATED_AT).field(IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT).interval(bucketSize).minDocCount(0L).format(DateUtils.DATETIME_FORMAT).timeZone(TimeZone.getTimeZone("GMT").getID()).offset(offsetInSeconds + "s").extendedBounds(startTime, endTime - 1_000L);
dateHistogram = addEffortAggregationIfNeeded(query, dateHistogram);
return Optional.of(dateHistogram);
}
Aggregations