use of org.elasticsearch.search.aggregations.AggregationBuilder 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);
}
use of org.elasticsearch.search.aggregations.AggregationBuilder in project sonarqube by SonarSource.
the class IssueIndex method newSecurityReportSubAggregations.
private static AggregationBuilder newSecurityReportSubAggregations(AggregationBuilder categoriesAggs, boolean includeCwe, @Nullable Collection<String> cwesInCategory) {
AggregationBuilder aggregationBuilder = addSecurityReportIssueCountAggregations(categoriesAggs);
if (includeCwe) {
final TermsAggregationBuilder cwesAgg = AggregationBuilders.terms(AGG_CWES).field(FIELD_ISSUE_CWE).size(MAX_FACET_SIZE);
if (cwesInCategory != null) {
cwesAgg.includeExclude(new IncludeExclude(cwesInCategory.toArray(new String[0]), new String[0]));
}
categoriesAggs.subAggregation(addSecurityReportIssueCountAggregations(cwesAgg));
}
return aggregationBuilder;
}
use of org.elasticsearch.search.aggregations.AggregationBuilder in project sonarqube by SonarSource.
the class IssueIndex method addAssignedToMeFacetIfNeeded.
private void addAssignedToMeFacetIfNeeded(SearchOptions options, TopAggregationHelper aggregationHelper, SearchSourceBuilder esRequest) {
String uuid = userSession.getUuid();
if (options.getFacets().contains(ASSIGNED_TO_ME.getName()) && !StringUtils.isEmpty(uuid)) {
AggregationBuilder aggregation = aggregationHelper.buildTermTopAggregation(ASSIGNED_TO_ME.getName(), ASSIGNED_TO_ME.getTopAggregationDef(), ASSIGNED_TO_ME.getNumberOfTerms(), NO_EXTRA_FILTER, t -> aggregationHelper.getSubAggregationHelper().buildSelectedItemsAggregation(ASSIGNED_TO_ME.getName(), ASSIGNED_TO_ME.getTopAggregationDef(), new String[] { uuid }).ifPresent(t::subAggregation));
esRequest.aggregation(aggregation);
}
}
use of org.elasticsearch.search.aggregations.AggregationBuilder in project sonarqube by SonarSource.
the class IssueIndex method addSeverityFacetIfNeeded.
private static void addSeverityFacetIfNeeded(SearchOptions options, TopAggregationHelper aggregationHelper, SearchSourceBuilder esRequest) {
if (!options.getFacets().contains(PARAM_SEVERITIES)) {
return;
}
AggregationBuilder aggregation = aggregationHelper.buildTermTopAggregation(SEVERITIES.getName(), SEVERITIES.getTopAggregationDef(), SEVERITIES.getNumberOfTerms(), // Ignore severity of Security HotSpots
filter -> filter.mustNot(termQuery(FIELD_ISSUE_TYPE, SECURITY_HOTSPOT.name())), NO_OTHER_SUBAGGREGATION);
esRequest.aggregation(aggregation);
}
use of org.elasticsearch.search.aggregations.AggregationBuilder in project sonarqube by SonarSource.
the class RuleIndex method addActiveSeverityFacetIfNeeded.
private static void addActiveSeverityFacetIfNeeded(RuleQuery query, SearchOptions options, Map<String, AggregationBuilder> aggregations, StickyFacetBuilder stickyFacetBuilder) {
QProfileDto profile = query.getQProfile();
if (options.getFacets().contains(FACET_ACTIVE_SEVERITIES) && profile != null) {
// We are building a children aggregation on active rules
// so the rule filter has to be used as parent filter for active rules
// from which we remove filters that concern active rules ("activation")
HasParentQueryBuilder ruleFilter = JoinQueryBuilders.hasParentQuery(TYPE_RULE.getType(), stickyFacetBuilder.getStickyFacetFilter("activation"), false);
// Rebuilding the active rule filter without severities
BoolQueryBuilder childrenFilter = boolQuery();
addTermFilter(childrenFilter, FIELD_ACTIVE_RULE_PROFILE_UUID, profile.getRulesProfileUuid());
RuleIndex.addTermFilter(childrenFilter, FIELD_ACTIVE_RULE_INHERITANCE, query.getInheritance());
QueryBuilder activeRuleFilter = childrenFilter.must(ruleFilter);
AggregationBuilder activeSeverities = JoinAggregationBuilders.children(FACET_ACTIVE_SEVERITIES + "_children", TYPE_ACTIVE_RULE.getName()).subAggregation(AggregationBuilders.filter(FACET_ACTIVE_SEVERITIES + "_filter", activeRuleFilter).subAggregation(AggregationBuilders.terms(FACET_ACTIVE_SEVERITIES).field(FIELD_ACTIVE_RULE_SEVERITY).includeExclude(new IncludeExclude(Joiner.on('|').join(Severity.ALL), null)).size(Severity.ALL.size())));
aggregations.put(FACET_ACTIVE_SEVERITIES, AggregationBuilders.global(FACET_ACTIVE_SEVERITIES).subAggregation(activeSeverities));
}
}
Aggregations