use of org.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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));
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.AggregationBuilder 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));
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.AggregationBuilder in project vertigo by KleeGroup.
the class ESSearchRequestBuilder method appendFacetDefinition.
private static void appendFacetDefinition(final SearchQuery searchQuery, final SearchRequestBuilder searchRequestBuilder, final SearchIndexDefinition myIndexDefinition, final DtListState myListState, final boolean useHighlight) {
Assertion.checkNotNull(searchRequestBuilder);
// On ajoute le cluster, si présent
if (searchQuery.isClusteringFacet()) {
// si il y a un cluster on le place en premier
final FacetDefinition clusteringFacetDefinition = searchQuery.getClusteringFacetDefinition();
final AggregationBuilder aggregationBuilder = facetToAggregationBuilder(clusteringFacetDefinition);
final TopHitsAggregationBuilder topHitsBuilder = AggregationBuilders.topHits(TOPHITS_SUBAGGREGATION_NAME).size(myListState.getMaxRows().orElse(TOPHITS_SUBAGGREGATION_SIZE)).from(myListState.getSkipRows());
if (useHighlight) {
// .addHighlightedField("*"); HOW TO ?
topHitsBuilder.highlighter(new HighlightBuilder().numOfFragments(3));
}
if (myListState.getSortFieldName().isPresent()) {
topHitsBuilder.sort(getFieldSortBuilder(myIndexDefinition, myListState));
}
aggregationBuilder.subAggregation(topHitsBuilder);
// We fetch source, because it's our only source to create result list
searchRequestBuilder.addAggregation(aggregationBuilder);
}
// Puis les facettes liées à la query, si présent
if (searchQuery.getFacetedQuery().isPresent()) {
final FacetedQueryDefinition facetedQueryDefinition = searchQuery.getFacetedQuery().get().getDefinition();
final Collection<FacetDefinition> facetDefinitions = new ArrayList<>(facetedQueryDefinition.getFacetDefinitions());
if (searchQuery.isClusteringFacet() && facetDefinitions.contains(searchQuery.getClusteringFacetDefinition())) {
facetDefinitions.remove(searchQuery.getClusteringFacetDefinition());
}
for (final FacetDefinition facetDefinition : facetDefinitions) {
final AggregationBuilder aggregationBuilder = facetToAggregationBuilder(facetDefinition);
final BoolQueryBuilder aggsFilterBoolQueryBuilder = QueryBuilders.boolQuery();
for (final FacetDefinition filterFacetDefinition : searchQuery.getFacetedQuery().get().getDefinition().getFacetDefinitions()) {
if (filterFacetDefinition.isMultiSelectable() && !facetDefinition.equals(filterFacetDefinition)) {
// on ne doit refiltrer que les multiSelectable (les autres sont dans le filter de la request), sauf la facet qu'on est entrain de traiter
appendSelectedFacetValuesFilter(aggsFilterBoolQueryBuilder, searchQuery.getFacetedQuery().get().getSelectedFacetValues().getFacetValues(filterFacetDefinition));
}
}
if (aggsFilterBoolQueryBuilder.hasClauses()) {
final AggregationBuilder filterAggregationBuilder = AggregationBuilders.filter(facetDefinition.getName() + "_FILTER", aggsFilterBoolQueryBuilder);
filterAggregationBuilder.subAggregation(aggregationBuilder);
searchRequestBuilder.addAggregation(filterAggregationBuilder);
} else {
searchRequestBuilder.addAggregation(aggregationBuilder);
}
}
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.AggregationBuilder in project vertexium by visallo.
the class ElasticsearchSearchQueryBase method getElasticsearchTermsAggregations.
protected List<AggregationBuilder> getElasticsearchTermsAggregations(TermsAggregation agg) {
List<AggregationBuilder> termsAggs = new ArrayList<>();
String fieldName = agg.getPropertyName();
if (Edge.LABEL_PROPERTY_NAME.equals(fieldName) || ExtendedDataRow.TABLE_NAME.equals(fieldName)) {
TermsAggregationBuilder termsAgg = AggregationBuilders.terms(createAggregationName(agg.getAggregationName(), "0"));
termsAgg.field(fieldName);
if (agg.getSize() != null) {
termsAgg.size(agg.getSize());
}
termsAgg.shardSize(termAggregationShardSize);
termsAggs.add(termsAgg);
} else {
PropertyDefinition propertyDefinition = getPropertyDefinition(fieldName);
for (String propertyName : getPropertyNames(fieldName)) {
boolean exactMatchProperty = isExactMatchPropertyDefinition(propertyDefinition);
String propertyNameWithSuffix;
if (exactMatchProperty) {
propertyNameWithSuffix = propertyName + Elasticsearch5SearchIndex.EXACT_MATCH_PROPERTY_NAME_SUFFIX;
} else {
propertyNameWithSuffix = propertyName;
}
String visibilityHash = getSearchIndex().getPropertyVisibilityHashFromPropertyName(propertyNameWithSuffix);
String aggregationName = createAggregationName(agg.getAggregationName(), visibilityHash);
TermsAggregationBuilder termsAgg = AggregationBuilders.terms(aggregationName);
termsAgg.field(propertyNameWithSuffix);
if (agg.getSize() != null) {
termsAgg.size(agg.getSize());
}
termsAgg.shardSize(termAggregationShardSize);
if (exactMatchProperty && propertyDefinition.getTextIndexHints().contains(TextIndexHint.FULL_TEXT)) {
termsAgg.subAggregation(AggregationBuilders.topHits(TOP_HITS_AGGREGATION_NAME).fetchSource(new String[] { propertyName }, new String[0]).size(1));
}
for (AggregationBuilder subAgg : getElasticsearchAggregations(agg.getNestedAggregations())) {
termsAgg.subAggregation(subAgg);
}
termsAggs.add(termsAgg);
}
}
return termsAggs;
}
Aggregations