use of org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude 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.bucket.terms.IncludeExclude 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));
}
}
use of org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude in project sonarqube by SonarSource.
the class RuleIndex method addStatusFacetIfNeeded.
private static void addStatusFacetIfNeeded(SearchOptions options, Map<String, AggregationBuilder> aggregations, StickyFacetBuilder stickyFacetBuilder) {
if (options.getFacets().contains(FACET_STATUSES)) {
BoolQueryBuilder facetFilter = stickyFacetBuilder.getStickyFacetFilter(FIELD_RULE_STATUS);
AggregationBuilder statuses = AggregationBuilders.filter(FACET_STATUSES + "_filter", facetFilter).subAggregation(AggregationBuilders.terms(FACET_STATUSES).field(FIELD_RULE_STATUS).includeExclude(new IncludeExclude(Joiner.on('|').join(ALL_STATUSES_EXCEPT_REMOVED), RuleStatus.REMOVED.toString())).size(ALL_STATUSES_EXCEPT_REMOVED.size()));
aggregations.put(FACET_STATUSES, AggregationBuilders.global(FACET_STATUSES).subAggregation(statuses));
}
}
Aggregations