org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude Java Examples

The following examples show how to use org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlogRepositoryCustomImpl.java    From Spring-5.0-Projects with MIT License 8 votes vote down vote up
public List<Comment> getCommentsForStatus(String status,int from, int size) {
	
   IncludeExclude includeExclude = new IncludeExclude(status, null);
	
   NestedAggregationBuilder aggregation = AggregationBuilders.nested("aggChild", "comments").
								  subAggregation(AggregationBuilders.terms("aggStatsComment").
								  field("comments.status").
								  includeExclude(includeExclude).
								  subAggregation(AggregationBuilders.topHits("aggSortComment").size(10).sort("comments.createdDate", SortOrder.DESC))
	);

	SearchResponse response = elasticsearchTemplate.getClient().prepareSearch("blog")
	  .setTypes("blog")
	  .addAggregation(aggregation)
	  .execute().actionGet();
	
	List<Aggregation> responseAgg = response.getAggregations().asList();
	
	return getAllCommentsWithStatusFromJson(responseAgg.get(0).toString());
	
}
 
Example #2
Source File: ElasticQueryBuilder.java    From vind with Apache License 2.0 5 votes vote down vote up
public static SearchSourceBuilder buildSuggestionQuery(ExecutableSuggestionSearch search, DocumentFactory factory) {

        final String searchContext = search.getSearchContext();

        final SearchSourceBuilder searchSource = new SearchSourceBuilder()
                .size(0);

        final BoolQueryBuilder filterSuggestions = QueryBuilders.boolQuery()
                .must(QueryBuilders.matchAllQuery())
                .filter(buildFilterQuery(search.getFilter(), factory, searchContext));

        searchSource.query(filterSuggestions);

//        if(search.getTimeZone() != null) {
//            query.set(CommonParams.TZ,search.getTimeZone());
//        }

        final List<String> suggestionFieldNames =
                Lists.newArrayList(getSuggestionFieldNames(search, factory, searchContext));

        suggestionFieldNames.stream()
                .map(field -> AggregationBuilders
                        .terms(FieldUtil.getSourceFieldName(field.replaceAll(".suggestion", ""), searchContext))
                        .field(field)
                        .includeExclude(
                                new IncludeExclude(Suggester.getSuggestionRegex(search.getInput()), null))
                )
                .forEach(searchSource::aggregation);

        final SuggestBuilder suggestBuilder = new SuggestBuilder();
        suggestBuilder.setGlobalText(search.getInput());
        suggestionFieldNames
                .forEach(fieldName -> suggestBuilder
                        .addSuggestion(
                                FieldUtil.getSourceFieldName(fieldName.replaceAll(".suggestion", ""), searchContext),
                                SuggestBuilders.termSuggestion(fieldName.concat("_experimental")).prefixLength(0)));

        searchSource.suggest(suggestBuilder);
        return searchSource;
    }
 
Example #3
Source File: ElasticQueryBuilder.java    From vind with Apache License 2.0 4 votes vote down vote up
private static void setTermOptions(TermsAggregationBuilder agg, TermFacetOption option) {
    if(Objects.nonNull(option.getPrefix())) {
        agg.includeExclude(new IncludeExclude(option.getPrefix() + ".*", null));
    }
    if(Objects.nonNull(option.getLimit())) {
        agg.size(option.getLimit());
    }

    if(Objects.nonNull(option.getMethod())) {
        log.warn("Elasticearch backend implementation does not support set method for term facets");
    }

    if(Objects.nonNull(option.getMincount())) {
        agg.minDocCount(option.getMincount());
    }

    if(Objects.nonNull(option.getOffset())) {
        log.warn("Elasticearch backend implementation does not support set offset for term facets");
    }

    if(Objects.nonNull(option.getOverrefine())) {
        log.warn("Elasticearch backend implementation does not support set overrefine for term facets");
    }

    if(Objects.nonNull(option.getOverrequest())) {
        log.warn("Elasticearch backend implementation does not support set overrequest for term facets");
    }

    if(Objects.nonNull(option.getSort())) {
        log.warn("Elasticearch backend implementation does not support set sorting for term facets");
    }

    if(Objects.nonNull(option.isAllBuckets())) {
        log.warn("Elasticearch backend implementation does not support set all Buckets for term facets");
    }

    if(Objects.nonNull(option.isMissing())) {
        agg.missing("");
    }

    if(Objects.nonNull(option.isNumBuckets())) {
        log.warn("Elasticearch backend implementation does not support set numBuckets for term facets");
    }

    if(Objects.nonNull(option.isRefine())) {
        log.warn("Elasticearch backend implementation does not support set refine for term facets");
    }
}