Search in sources :

Example 26 with FilterAggregationBuilder

use of org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder in project sonarqube by SonarSource.

the class StickyFacetBuilder method addSelectedItemsToFacet.

public FilterAggregationBuilder addSelectedItemsToFacet(String fieldName, String facetName, FilterAggregationBuilder facetTopAggregation, Object... selected) {
    if (selected.length <= 0) {
        return facetTopAggregation;
    }
    String includes = Arrays.stream(selected).filter(Objects::nonNull).map(s -> EsUtils.escapeSpecialRegexChars(s.toString())).collect(PIPE_JOINER);
    TermsBuilder selectedTerms = AggregationBuilders.terms(facetName + "_selected").field(fieldName).include(includes);
    if (subAggregation != null) {
        selectedTerms = selectedTerms.subAggregation(subAggregation);
    }
    facetTopAggregation.subAggregation(selectedTerms);
    return facetTopAggregation;
}
Also used : QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Arrays(java.util.Arrays) TermsBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder) AbstractAggregationBuilder(org.elasticsearch.search.aggregations.AbstractAggregationBuilder) AggregationBuilder(org.elasticsearch.search.aggregations.AggregationBuilder) QueryBuilders.boolQuery(org.elasticsearch.index.query.QueryBuilders.boolQuery) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) AggregationBuilders(org.elasticsearch.search.aggregations.AggregationBuilders) FilterAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) Collectors(java.util.stream.Collectors) Order(org.elasticsearch.search.aggregations.bucket.terms.Terms.Order) Objects(java.util.Objects) Map(java.util.Map) Collector(java.util.stream.Collector) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Nullable(javax.annotation.Nullable) ArrayUtils(org.apache.commons.lang.ArrayUtils) TermsBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder) Objects(java.util.Objects)

Example 27 with FilterAggregationBuilder

use of org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder in project sonarqube by SonarSource.

the class IssueIndex method addAssignedToMeFacetIfNeeded.

private void addAssignedToMeFacetIfNeeded(SearchRequestBuilder builder, SearchOptions options, IssueQuery query, Map<String, QueryBuilder> filters, QueryBuilder queryBuilder) {
    String login = userSession.getLogin();
    if (!options.getFacets().contains(FACET_ASSIGNED_TO_ME) || StringUtils.isEmpty(login)) {
        return;
    }
    String fieldName = IssueIndexDefinition.FIELD_ISSUE_ASSIGNEE;
    String facetName = FACET_ASSIGNED_TO_ME;
    // Same as in super.stickyFacetBuilder
    StickyFacetBuilder assignedToMeFacetBuilder = newStickyFacetBuilder(query, filters, queryBuilder);
    BoolQueryBuilder facetFilter = assignedToMeFacetBuilder.getStickyFacetFilter(IS_ASSIGNED_FILTER, fieldName);
    FilterAggregationBuilder facetTopAggregation = AggregationBuilders.filter(facetName + "__filter").filter(facetFilter).subAggregation(addEffortAggregationIfNeeded(query, AggregationBuilders.terms(facetName + "__terms").field(fieldName).include(escapeSpecialRegexChars(login))));
    builder.addAggregation(AggregationBuilders.global(facetName).subAggregation(facetTopAggregation));
}
Also used : FilterAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) StickyFacetBuilder(org.sonar.server.es.StickyFacetBuilder)

Example 28 with FilterAggregationBuilder

use of org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder in project graylog2-server by Graylog2.

the class Searches method terms.

public TermsResult terms(String field, int size, String query, String filter, TimeRange range, Sorting.Direction sorting) {
    Terms.Order termsOrder;
    if (size == 0) {
        size = 50;
    }
    if (sorting == Sorting.Direction.DESC) {
        termsOrder = Terms.Order.count(false);
    } else {
        termsOrder = Terms.Order.count(true);
    }
    SearchRequestBuilder srb;
    if (filter == null) {
        srb = standardSearchRequest(query, determineAffectedIndices(range, null), range);
    } else {
        srb = filteredSearchRequest(query, filter, determineAffectedIndices(range, filter), range);
    }
    FilterAggregationBuilder builder = AggregationBuilders.filter(AGG_FILTER).subAggregation(AggregationBuilders.terms(AGG_TERMS).field(field).size(size).order(termsOrder)).subAggregation(AggregationBuilders.missing("missing").field(field)).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 TermsResult(f.getAggregations().get(AGG_TERMS), f.getAggregations().get("missing"), f.getDocCount(), query, request.source(), r.getTook());
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) FilterAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) Filter(org.elasticsearch.search.aggregations.bucket.filter.Filter) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) TermsResult(org.graylog2.indexer.results.TermsResult) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 29 with FilterAggregationBuilder

use of org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder in project graylog2-server by Graylog2.

the class Searches method histogram.

public HistogramResult histogram(String query, DateHistogramInterval interval, String filter, TimeRange range) {
    FilterAggregationBuilder builder = AggregationBuilders.filter(AGG_FILTER).subAggregation(AggregationBuilders.dateHistogram(AGG_HISTOGRAM).field("timestamp").interval(interval.toESInterval())).filter(standardAggregationFilters(range, filter));
    QueryStringQueryBuilder qs = queryStringQuery(query);
    qs.allowLeadingWildcard(configuration.isAllowLeadingWildcardSearches());
    final Set<String> affectedIndices = determineAffectedIndices(range, filter);
    final SearchRequestBuilder srb = c.prepareSearch(affectedIndices.toArray(new String[affectedIndices.size()])).setIndicesOptions(IndicesOptions.lenientExpandOpen()).setQuery(qs).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 DateHistogramResult(f.getAggregations().get(AGG_HISTOGRAM), query, request.source(), interval, r.getTook());
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) DateHistogramResult(org.graylog2.indexer.results.DateHistogramResult) FilterAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) Filter(org.elasticsearch.search.aggregations.bucket.filter.Filter) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 30 with FilterAggregationBuilder

use of org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder in project fess by codelibs.

the class EsAbstractConditionAggregation method regFilterA.

protected FilterAggregationBuilder regFilterA(String name, QueryBuilder filter) {
    FilterAggregationBuilder builder = AggregationBuilders.filter(name, filter);
    regA(builder);
    return builder;
}
Also used : FilterAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)

Aggregations

FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)52 SearchRequest (org.elasticsearch.action.search.SearchRequest)6 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)6 SearchResponse (org.elasticsearch.action.search.SearchResponse)6 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)6 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)5 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)4 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)2 StickyFacetBuilder (org.sonar.server.es.StickyFacetBuilder)2 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Collector (java.util.stream.Collector)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 ArrayUtils (org.apache.commons.lang.ArrayUtils)1 AccessTokenCA (org.codelibs.fess.es.config.cbean.ca.AccessTokenCA)1 BadWordCA (org.codelibs.fess.es.config.cbean.ca.BadWordCA)1