use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder in project graylog2-server by Graylog2.
the class Searches method termsStats.
public TermsStatsResult termsStats(String keyField, String valueField, TermsStatsOrder order, int size, String query, String filter, TimeRange range) {
if (size == 0) {
size = 50;
}
SearchRequestBuilder srb;
if (filter == null) {
srb = standardSearchRequest(query, determineAffectedIndices(range, filter), range);
} else {
srb = filteredSearchRequest(query, filter, determineAffectedIndices(range, filter), range);
}
Terms.Order termsOrder;
switch(order) {
case COUNT:
termsOrder = Terms.Order.count(true);
break;
case REVERSE_COUNT:
termsOrder = Terms.Order.count(false);
break;
case TERM:
termsOrder = Terms.Order.term(true);
break;
case REVERSE_TERM:
termsOrder = Terms.Order.term(false);
break;
case MIN:
termsOrder = Terms.Order.aggregation(AGG_STATS, "min", true);
break;
case REVERSE_MIN:
termsOrder = Terms.Order.aggregation(AGG_STATS, "min", false);
break;
case MAX:
termsOrder = Terms.Order.aggregation(AGG_STATS, "max", true);
break;
case REVERSE_MAX:
termsOrder = Terms.Order.aggregation(AGG_STATS, "max", false);
break;
case MEAN:
termsOrder = Terms.Order.aggregation(AGG_STATS, "avg", true);
break;
case REVERSE_MEAN:
termsOrder = Terms.Order.aggregation(AGG_STATS, "avg", false);
break;
case TOTAL:
termsOrder = Terms.Order.aggregation(AGG_STATS, "sum", true);
break;
case REVERSE_TOTAL:
termsOrder = Terms.Order.aggregation(AGG_STATS, "sum", false);
break;
default:
termsOrder = Terms.Order.count(true);
}
FilterAggregationBuilder builder = AggregationBuilders.filter(AGG_FILTER).subAggregation(AggregationBuilders.terms(AGG_TERMS_STATS).field(keyField).subAggregation(AggregationBuilders.stats(AGG_STATS).field(valueField)).order(termsOrder).size(size)).filter(standardAggregationFilters(range, filter));
srb.addAggregation(builder);
final SearchRequest request = srb.request();
SearchResponse r = c.search(request).actionGet();
recordEsMetrics(r, range);
final Filter f = r.getAggregations().get(AGG_FILTER);
return new TermsStatsResult(f.getAggregations().get(AGG_TERMS_STATS), query, request.source(), r.getTook());
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder in project fess by codelibs.
the class BsDataConfigToRoleCA method filter.
// ===================================================================================
// Aggregation Set
// =========
public void filter(String name, EsAbstractConditionQuery.OperatorCall<BsDataConfigToRoleCQ> queryLambda, ConditionOptionCall<FilterAggregationBuilder> opLambda, OperatorCall<BsDataConfigToRoleCA> aggsLambda) {
DataConfigToRoleCQ cq = new DataConfigToRoleCQ();
if (queryLambda != null) {
queryLambda.callback(cq);
}
FilterAggregationBuilder builder = regFilterA(name, cq.getQuery());
if (opLambda != null) {
opLambda.callback(builder);
}
if (aggsLambda != null) {
DataConfigToRoleCA ca = new DataConfigToRoleCA();
aggsLambda.callback(ca);
ca.getAggregationBuilderList().forEach(builder::subAggregation);
}
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder in project fess by codelibs.
the class BsWebConfigToLabelCA method filter.
// ===================================================================================
// Aggregation Set
// =========
public void filter(String name, EsAbstractConditionQuery.OperatorCall<BsWebConfigToLabelCQ> queryLambda, ConditionOptionCall<FilterAggregationBuilder> opLambda, OperatorCall<BsWebConfigToLabelCA> aggsLambda) {
WebConfigToLabelCQ cq = new WebConfigToLabelCQ();
if (queryLambda != null) {
queryLambda.callback(cq);
}
FilterAggregationBuilder builder = regFilterA(name, cq.getQuery());
if (opLambda != null) {
opLambda.callback(builder);
}
if (aggsLambda != null) {
WebConfigToLabelCA ca = new WebConfigToLabelCA();
aggsLambda.callback(ca);
ca.getAggregationBuilderList().forEach(builder::subAggregation);
}
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder in project fess by codelibs.
the class BsSearchFieldLogCA method filter.
// ===================================================================================
// Aggregation Set
// =========
public void filter(String name, EsAbstractConditionQuery.OperatorCall<BsSearchFieldLogCQ> queryLambda, ConditionOptionCall<FilterAggregationBuilder> opLambda, OperatorCall<BsSearchFieldLogCA> aggsLambda) {
SearchFieldLogCQ cq = new SearchFieldLogCQ();
if (queryLambda != null) {
queryLambda.callback(cq);
}
FilterAggregationBuilder builder = regFilterA(name, cq.getQuery());
if (opLambda != null) {
opLambda.callback(builder);
}
if (aggsLambda != null) {
SearchFieldLogCA ca = new SearchFieldLogCA();
aggsLambda.callback(ca);
ca.getAggregationBuilderList().forEach(builder::subAggregation);
}
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder in project sonarqube by SonarSource.
the class TopAggregationHelperTest method buildTermTopAggregation_has_empty_filter_when_FiltersComputer_returns_empty_for_TopAggregation.
@Test
public void buildTermTopAggregation_has_empty_filter_when_FiltersComputer_returns_empty_for_TopAggregation() {
SimpleFieldTopAggregationDefinition topAggregation = new SimpleFieldTopAggregationDefinition("bar", false);
SimpleFieldTopAggregationDefinition otherTopAggregation = new SimpleFieldTopAggregationDefinition("acme", false);
BoolQueryBuilder otherFilter = boolQuery();
when(filtersComputer.getTopAggregationFilter(topAggregation)).thenReturn(Optional.empty());
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()).isEqualTo(boolQuery()).isNotSameAs(otherFilter);
}
Aggregations