Search in sources :

Example 6 with IncludeExclude

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;
}
Also used : TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) 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) IncludeExclude(org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude)

Example 7 with IncludeExclude

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));
    }
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) AggregationBuilder(org.elasticsearch.search.aggregations.AggregationBuilder) TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) IncludeExclude(org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude) HasParentQueryBuilder(org.elasticsearch.join.query.HasParentQueryBuilder) HasParentQueryBuilder(org.elasticsearch.join.query.HasParentQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder)

Example 8 with IncludeExclude

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));
    }
}
Also used : AggregationBuilder(org.elasticsearch.search.aggregations.AggregationBuilder) TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) IncludeExclude(org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude)

Aggregations

IncludeExclude (org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude)8 TermsAggregationBuilder (org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder)8 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)4 AggregationBuilder (org.elasticsearch.search.aggregations.AggregationBuilder)4 Arrays (java.util.Arrays)3 Nullable (javax.annotation.Nullable)3 SearchResponse (org.elasticsearch.action.search.SearchResponse)3 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)3 AggregationBuilders (org.elasticsearch.search.aggregations.AggregationBuilders)3 BucketOrder (org.elasticsearch.search.aggregations.BucketOrder)3 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)3 Math.max (java.lang.Math.max)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Function (java.util.function.Function)2 Collector (java.util.stream.Collector)2 Collectors (java.util.stream.Collectors)2 SearchRequest (org.elasticsearch.action.search.SearchRequest)2 QueryBuilders.boolQuery (org.elasticsearch.index.query.QueryBuilders.boolQuery)2 FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)2