use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder in project sonarqube by SonarSource.
the class TopAggregationHelperTest method buildTermTopAggregation_adds_filter_from_FiltersComputer_for_TopAggregation.
@Test
public void buildTermTopAggregation_adds_filter_from_FiltersComputer_for_TopAggregation() {
SimpleFieldTopAggregationDefinition topAggregation = new SimpleFieldTopAggregationDefinition("bar", false);
SimpleFieldTopAggregationDefinition otherTopAggregation = new SimpleFieldTopAggregationDefinition("acme", false);
BoolQueryBuilder computerFilter = boolQuery();
BoolQueryBuilder otherFilter = boolQuery();
when(filtersComputer.getTopAggregationFilter(topAggregation)).thenReturn(Optional.of(computerFilter));
when(filtersComputer.getTopAggregationFilter(otherTopAggregation)).thenReturn(Optional.of(otherFilter));
String topAggregationName = randomAlphabetic(10);
TermsAggregationBuilder termSubAgg = AggregationBuilders.terms("foo");
when(subAggregationHelper.buildTermsAggregation(topAggregationName, topAggregation, null)).thenReturn(termSubAgg);
FilterAggregationBuilder aggregationBuilder = underTest.buildTermTopAggregation(topAggregationName, topAggregation, null, NO_EXTRA_FILTER, NO_OTHER_SUBAGGREGATION);
assertThat(aggregationBuilder.getName()).isEqualTo(topAggregationName);
assertThat(aggregationBuilder.getFilter()).isSameAs(computerFilter);
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder in project sonarqube by SonarSource.
the class SubAggregationHelper method buildSelectedItemsAggregation.
public <T> Optional<TermsAggregationBuilder> buildSelectedItemsAggregation(String name, TopAggregationDefinition<?> topAggregation, T[] selected) {
if (selected.length <= 0) {
return Optional.empty();
}
String includes = Arrays.stream(selected).filter(Objects::nonNull).map(s -> EsUtils.escapeSpecialRegexChars(s.toString())).collect(PIPE_JOINER);
TermsAggregationBuilder selectedTerms = AggregationBuilders.terms(name + Facets.SELECTED_SUB_AGG_NAME_SUFFIX).size(max(MAXIMUM_NUMBER_OF_SELECTED_ITEMS_WHOSE_DOC_COUNT_WILL_BE_CALCULATED, includes.length())).field(topAggregation.getFilterScope().getFieldName()).includeExclude(new IncludeExclude(includes, null));
if (subAggregation != null) {
selectedTerms = selectedTerms.subAggregation(subAggregation);
}
return of(selectedTerms);
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder 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.bucket.terms.TermsAggregationBuilder in project sonarqube by SonarSource.
the class SubAggregationHelperTest method buildTermsAggregation_adds_custom_size_if_TermTopAggregation_specifies_one.
@Test
public void buildTermsAggregation_adds_custom_size_if_TermTopAggregation_specifies_one() {
String aggName = randomAlphabetic(10);
int customSize = 1 + new Random().nextInt(400);
SimpleFieldTopAggregationDefinition topAggregation = new SimpleFieldTopAggregationDefinition("bar", false);
Stream.of(underTest, underTestWithCustomSubAgg, underTestWithCustomsSubAggAndOrder).forEach(t -> {
TermsAggregationBuilder agg = t.buildTermsAggregation(aggName, topAggregation, customSize);
assertThat(agg.getName()).isEqualTo(aggName);
assertThat(agg.field()).isEqualTo(topAggregation.getFilterScope().getFieldName());
assertThat(agg.size()).isEqualTo(customSize);
});
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder in project sonarqube by SonarSource.
the class SubAggregationHelperTest method buildTermsAggregation_adds_custom_order_from_constructor.
@Test
public void buildTermsAggregation_adds_custom_order_from_constructor() {
String aggName = randomAlphabetic(10);
SimpleFieldTopAggregationDefinition topAggregation = new SimpleFieldTopAggregationDefinition("bar", false);
TermsAggregationBuilder agg = underTestWithCustomsSubAggAndOrder.buildTermsAggregation(aggName, topAggregation, null);
assertThat(agg.getName()).isEqualTo(aggName);
assertThat(agg.field()).isEqualTo(topAggregation.getFilterScope().getFieldName());
assertThat(agg.order()).isEqualTo(BucketOrder.compound(customOrder, ES_BUILTIN_TIE_BREAKER));
}
Aggregations