Java Code Examples for org.elasticsearch.search.aggregations.AggregationBuilders#filter()
The following examples show how to use
org.elasticsearch.search.aggregations.AggregationBuilders#filter() .
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: SalesTrendsQueryAdapter.java From micronaut-microservices-poc with Apache License 2.0 | 6 votes |
@Override SearchRequest buildQuery() { SearchRequest searchRequest = new SearchRequest("policy_stats") .types("policy_type"); BoolQueryBuilder filterBuilder = QueryBuilders.boolQuery(); if (query.getFilterByProductCode()!=null) { filterBuilder.must(QueryBuilders.termQuery("productCode.keyword", query.getFilterByProductCode())); } if (query.getFilterBySalesDate()!=null){ RangeQueryBuilder datesRange = QueryBuilders .rangeQuery("from") .gte(query.getFilterBySalesDate().getFrom().toString()) .lt(query.getFilterBySalesDate().getTo().toString()); filterBuilder.must(datesRange); } AggregationBuilder aggBuilder = AggregationBuilders.filter("agg_filter",filterBuilder); DateHistogramAggregationBuilder histBuilder = AggregationBuilders .dateHistogram("sales") .field("from") .dateHistogramInterval(query.getAggregationUnit().toDateHistogramInterval()) .subAggregation(AggregationBuilders.sum("total_premium").field("totalPremium")); aggBuilder.subAggregation(histBuilder); SearchSourceBuilder srcBuilder = new SearchSourceBuilder() .aggregation(aggBuilder) .size(0); searchRequest.source(srcBuilder); return searchRequest; }
Example 2
Source File: TotalSalesQueryAdapter.java From micronaut-microservices-poc with Apache License 2.0 | 5 votes |
@Override SearchRequest buildQuery() { SearchRequest searchRequest = new SearchRequest("policy_stats") .types("policy_type"); BoolQueryBuilder filterBuilder = QueryBuilders.boolQuery(); if (query.getFilterByProductCode()!=null) { filterBuilder.must(QueryBuilders.termQuery("productCode.keyword", query.getFilterByProductCode())); } if (query.getFilterBySalesDate()!=null){ RangeQueryBuilder datesRange = QueryBuilders .rangeQuery("from") .gte(query.getFilterBySalesDate().getFrom().toString()) .lt(query.getFilterBySalesDate().getTo().toString()); filterBuilder.must(datesRange); } AggregationBuilder aggBuilder = AggregationBuilders.filter("agg_filter",filterBuilder); TermsAggregationBuilder sumAggBuilder = AggregationBuilders .terms("count_by_product") .field("productCode.keyword") .subAggregation(AggregationBuilders.sum("total_premium").field("totalPremium")); aggBuilder.subAggregation(sumAggBuilder); SearchSourceBuilder srcBuilder = new SearchSourceBuilder() .aggregation(aggBuilder) .size(0); searchRequest.source(srcBuilder); return searchRequest; }
Example 3
Source File: AgentSalesQueryAdapter.java From micronaut-microservices-poc with Apache License 2.0 | 5 votes |
@Override SearchRequest buildQuery() { SearchRequest searchRequest = new SearchRequest("policy_stats") .types("policy_type"); BoolQueryBuilder filterBuilder = QueryBuilders.boolQuery(); if (query.getFilterByAgentLogin() != null) { filterBuilder.must(QueryBuilders.termQuery("agentLogin.keyword", query.getFilterByAgentLogin())); } if (query.getFilterByProductCode() != null) { filterBuilder.must(QueryBuilders.termQuery("productCode.keyword", query.getFilterByProductCode())); } if (query.getFilterBySalesDate() != null) { RangeQueryBuilder datesRange = QueryBuilders .rangeQuery("from") .gte(query.getFilterBySalesDate().getFrom().toString()) .lt(query.getFilterBySalesDate().getTo().toString()); filterBuilder.must(datesRange); } AggregationBuilder aggBuilder = AggregationBuilders.filter("agg_filter", filterBuilder); TermsAggregationBuilder sumAggBuilder = AggregationBuilders .terms("count_by_agent") .field("agentLogin.keyword") .subAggregation(AggregationBuilders.sum("total_premium").field("totalPremium")); aggBuilder.subAggregation(sumAggBuilder); SearchSourceBuilder srcBuilder = new SearchSourceBuilder() .aggregation(aggBuilder) .size(0); searchRequest.source(srcBuilder); return searchRequest; }
Example 4
Source File: GroupParser.java From sql4es with Apache License 2.0 | 5 votes |
public FilterAggregationBuilder addCountDistinctAggregation(QueryState state){ FilterAggregationBuilder result = AggregationBuilders.filter("cardinality_aggs", QueryBuilders.matchAllQuery()); for(Column col : state.getHeading().columns()){ result.subAggregation( AggregationBuilders.cardinality(col.getLabel()).field(col.getColumn()).precisionThreshold(state.getIntProp(Utils.PROP_PRECISION_THRESHOLD, 3000)) ); } return result; }
Example 5
Source File: GroupParser.java From sql4es with Apache License 2.0 | 4 votes |
/** * Adds a Filtered Aggregation used to aggregate all results for a query without having a Group By */ public FilterAggregationBuilder buildFilterAggregation(QueryBuilder query, Heading heading){ FilterAggregationBuilder filterAgg = AggregationBuilders.filter("filter", query); addMetrics(filterAgg, heading, false); return filterAgg; }
Example 6
Source File: SimpleSearchQueryBuilder.java From onetwo with Apache License 2.0 | 4 votes |
public SimpleAggregationBuilder<SimpleSearchQueryBuilder> aggFilter(String name) { FilterAggregationBuilder filterAgg = AggregationBuilders.filter(name); return agg(filterAgg); }
Example 7
Source File: EsAbstractConditionAggregation.java From fess with Apache License 2.0 | 4 votes |
protected FilterAggregationBuilder regFilterA(String name, QueryBuilder filter) { FilterAggregationBuilder builder = AggregationBuilders.filter(name, filter); regA(builder); return builder; }
Example 8
Source File: EsAbstractConditionAggregation.java From fess with Apache License 2.0 | 4 votes |
protected FilterAggregationBuilder regFilterA(String name, QueryBuilder filter) { FilterAggregationBuilder builder = AggregationBuilders.filter(name, filter); regA(builder); return builder; }
Example 9
Source File: EsAbstractConditionAggregation.java From fess with Apache License 2.0 | 4 votes |
protected FilterAggregationBuilder regFilterA(String name, QueryBuilder filter) { FilterAggregationBuilder builder = AggregationBuilders.filter(name, filter); regA(builder); return builder; }