org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder Java Examples
The following examples show how to use
org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder.
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: DateHistogramAggregationMain.java From elasticsearch-pool with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { RestHighLevelClient client = HighLevelClient.getInstance(); try{ DateHistogramAggregationBuilder dateHistogramAggregationBuilder = AggregationBuilders.dateHistogram("ctm_date_histogram"); dateHistogramAggregationBuilder.field("ctm");//设置直方图针对的字段 dateHistogramAggregationBuilder.dateHistogramInterval(DateHistogramInterval.hours(6));//直方图每个分组对应的范围 dateHistogramAggregationBuilder.timeZone(DateTimeZone.forOffsetHours(8));//时区偏移 dateHistogramAggregationBuilder.keyed(true);//是否需要key名 dateHistogramAggregationBuilder.format("yyyy-MM-dd HH:mm");//key名格式 // dateHistogramAggregationBuilder.order(BucketOrder.aggregation("_key",true));//分组key的排序 // dateHistogramAggregationBuilder.minDocCount(0);//对于每个分组最少具有多少条数据,少于这个设置,则该分组不显示 // dateHistogramAggregationBuilder.extendedBounds(0,8000);//设置分组区间的下线和上线,只有当min_doc_count为0时有效 TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("cmd","weather_info"); SearchRequest searchRequest = new SearchRequest("serverlog_20180710");//限定index searchRequest.types("log");//限定type SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(termQueryBuilder); searchSourceBuilder.aggregation(dateHistogramAggregationBuilder); searchRequest.source(searchSourceBuilder); SearchResponse searchResponse = client.search(searchRequest); System.out.println(searchResponse); }finally{ HighLevelClient.close(); } }
Example #3
Source File: BsSearchLogCA.java From fess with Apache License 2.0 | 5 votes |
public void setRequestedAt_DateHistogram(String name, ConditionOptionCall<DateHistogramAggregationBuilder> opLambda, OperatorCall<BsSearchLogCA> aggsLambda) { DateHistogramAggregationBuilder builder = regDateHistogramA(name, "requestedAt"); if (opLambda != null) { opLambda.callback(builder); } if (aggsLambda != null) { SearchLogCA ca = new SearchLogCA(); aggsLambda.callback(ca); ca.getAggregationBuilderList().forEach(builder::subAggregation); } }
Example #4
Source File: BsFavoriteLogCA.java From fess with Apache License 2.0 | 5 votes |
public void setCreatedAt_DateHistogram(String name, ConditionOptionCall<DateHistogramAggregationBuilder> opLambda, OperatorCall<BsFavoriteLogCA> aggsLambda) { DateHistogramAggregationBuilder builder = regDateHistogramA(name, "createdAt"); if (opLambda != null) { opLambda.callback(builder); } if (aggsLambda != null) { FavoriteLogCA ca = new FavoriteLogCA(); aggsLambda.callback(ca); ca.getAggregationBuilderList().forEach(builder::subAggregation); } }
Example #5
Source File: BsClickLogCA.java From fess with Apache License 2.0 | 5 votes |
public void setRequestedAt_DateHistogram(String name, ConditionOptionCall<DateHistogramAggregationBuilder> opLambda, OperatorCall<BsClickLogCA> aggsLambda) { DateHistogramAggregationBuilder builder = regDateHistogramA(name, "requestedAt"); if (opLambda != null) { opLambda.callback(builder); } if (aggsLambda != null) { ClickLogCA ca = new ClickLogCA(); aggsLambda.callback(ca); ca.getAggregationBuilderList().forEach(builder::subAggregation); } }
Example #6
Source File: BsClickLogCA.java From fess with Apache License 2.0 | 5 votes |
public void setQueryRequestedAt_DateHistogram(String name, ConditionOptionCall<DateHistogramAggregationBuilder> opLambda, OperatorCall<BsClickLogCA> aggsLambda) { DateHistogramAggregationBuilder builder = regDateHistogramA(name, "queryRequestedAt"); if (opLambda != null) { opLambda.callback(builder); } if (aggsLambda != null) { ClickLogCA ca = new ClickLogCA(); aggsLambda.callback(ca); ca.getAggregationBuilderList().forEach(builder::subAggregation); } }
Example #7
Source File: BsUserInfoCA.java From fess with Apache License 2.0 | 5 votes |
public void setUpdatedAt_DateHistogram(String name, ConditionOptionCall<DateHistogramAggregationBuilder> opLambda, OperatorCall<BsUserInfoCA> aggsLambda) { DateHistogramAggregationBuilder builder = regDateHistogramA(name, "updatedAt"); if (opLambda != null) { opLambda.callback(builder); } if (aggsLambda != null) { UserInfoCA ca = new UserInfoCA(); aggsLambda.callback(ca); ca.getAggregationBuilderList().forEach(builder::subAggregation); } }
Example #8
Source File: BsUserInfoCA.java From fess with Apache License 2.0 | 5 votes |
public void setCreatedAt_DateHistogram(String name, ConditionOptionCall<DateHistogramAggregationBuilder> opLambda, OperatorCall<BsUserInfoCA> aggsLambda) { DateHistogramAggregationBuilder builder = regDateHistogramA(name, "createdAt"); if (opLambda != null) { opLambda.callback(builder); } if (aggsLambda != null) { UserInfoCA ca = new UserInfoCA(); aggsLambda.callback(ca); ca.getAggregationBuilderList().forEach(builder::subAggregation); } }
Example #9
Source File: HistogramAction.java From foxtrot with Apache License 2.0 | 5 votes |
private AbstractAggregationBuilder buildAggregation(HistogramRequest parameter) { DateHistogramInterval interval = Utils.getHistogramInterval(getParameter().getPeriod()); DateHistogramAggregationBuilder histogramBuilder = Utils.buildDateHistogramAggregation(getParameter().getField(), interval); if (!CollectionUtils.isNullOrEmpty(getParameter().getUniqueCountOn())) { histogramBuilder.subAggregation(Utils.buildCardinalityAggregation( getParameter().getUniqueCountOn(), parameter.accept(new CountPrecisionThresholdVisitorAdapter( elasticsearchTuningConfig.getPrecisionThreshold())))); } return histogramBuilder; }
Example #10
Source File: TrendAction.java From foxtrot with Apache License 2.0 | 5 votes |
private AbstractAggregationBuilder buildAggregation(TrendRequest request) { DateHistogramInterval interval = Utils.getHistogramInterval(request.getPeriod()); String field = request.getField(); DateHistogramAggregationBuilder histogramBuilder = Utils.buildDateHistogramAggregation(request.getTimestamp(), interval); if(!CollectionUtils.isNullOrEmpty(getParameter().getUniqueCountOn())) { histogramBuilder.subAggregation(Utils.buildCardinalityAggregation( getParameter().getUniqueCountOn(), request.accept(new CountPrecisionThresholdVisitorAdapter( elasticsearchTuningConfig.getPrecisionThreshold())))); } return Utils.buildTermsAggregation(Lists.newArrayList(new ResultSort(field, ResultSort.Order.asc)), Sets.newHashSet(histogramBuilder), elasticsearchTuningConfig.getAggregationSize()); }
Example #11
Source File: Utils.java From foxtrot with Apache License 2.0 | 5 votes |
public static DateHistogramAggregationBuilder buildDateHistogramAggregation( String field, DateHistogramInterval interval) { String metricKey = getDateHistogramKey(field); return AggregationBuilders.dateHistogram(metricKey) .minDocCount(0) .field(storedFieldName(field)) .timeZone(DateTimeZone.getDefault()) .dateHistogramInterval(interval); }
Example #12
Source File: EsAbstractConditionAggregation.java From fess with Apache License 2.0 | 4 votes |
protected DateHistogramAggregationBuilder regDateHistogramA(String name, String field) { DateHistogramAggregationBuilder builder = AggregationBuilders.dateHistogram(name).field(field); regA(builder); return builder; }
Example #13
Source File: EsAbstractConditionAggregation.java From fess with Apache License 2.0 | 4 votes |
protected DateHistogramAggregationBuilder regDateHistogramA(String name, String field) { DateHistogramAggregationBuilder builder = AggregationBuilders.dateHistogram(name).field(field); regA(builder); return builder; }
Example #14
Source File: EsAbstractConditionAggregation.java From fess with Apache License 2.0 | 4 votes |
protected DateHistogramAggregationBuilder regDateHistogramA(String name, String field) { DateHistogramAggregationBuilder builder = AggregationBuilders.dateHistogram(name).field(field); regA(builder); return builder; }
Example #15
Source File: BsSearchLogCA.java From fess with Apache License 2.0 | 4 votes |
public void setRequestedAt_DateHistogram(ConditionOptionCall<DateHistogramAggregationBuilder> opLambda, OperatorCall<BsSearchLogCA> aggsLambda) { setRequestedAt_DateHistogram("requestedAt", opLambda, aggsLambda); }
Example #16
Source File: BsSearchLogCA.java From fess with Apache License 2.0 | 4 votes |
public void setRequestedAt_DateHistogram(ConditionOptionCall<DateHistogramAggregationBuilder> opLambda) { setRequestedAt_DateHistogram("requestedAt", opLambda, null); }
Example #17
Source File: BsFavoriteLogCA.java From fess with Apache License 2.0 | 4 votes |
public void setCreatedAt_DateHistogram(ConditionOptionCall<DateHistogramAggregationBuilder> opLambda, OperatorCall<BsFavoriteLogCA> aggsLambda) { setCreatedAt_DateHistogram("createdAt", opLambda, aggsLambda); }
Example #18
Source File: BsFavoriteLogCA.java From fess with Apache License 2.0 | 4 votes |
public void setCreatedAt_DateHistogram(ConditionOptionCall<DateHistogramAggregationBuilder> opLambda) { setCreatedAt_DateHistogram("createdAt", opLambda, null); }
Example #19
Source File: BsClickLogCA.java From fess with Apache License 2.0 | 4 votes |
public void setRequestedAt_DateHistogram(ConditionOptionCall<DateHistogramAggregationBuilder> opLambda, OperatorCall<BsClickLogCA> aggsLambda) { setRequestedAt_DateHistogram("requestedAt", opLambda, aggsLambda); }
Example #20
Source File: BsClickLogCA.java From fess with Apache License 2.0 | 4 votes |
public void setRequestedAt_DateHistogram(ConditionOptionCall<DateHistogramAggregationBuilder> opLambda) { setRequestedAt_DateHistogram("requestedAt", opLambda, null); }
Example #21
Source File: BsUserInfoCA.java From fess with Apache License 2.0 | 4 votes |
public void setCreatedAt_DateHistogram(ConditionOptionCall<DateHistogramAggregationBuilder> opLambda) { setCreatedAt_DateHistogram("createdAt", opLambda, null); }
Example #22
Source File: BsClickLogCA.java From fess with Apache License 2.0 | 4 votes |
public void setQueryRequestedAt_DateHistogram(ConditionOptionCall<DateHistogramAggregationBuilder> opLambda, OperatorCall<BsClickLogCA> aggsLambda) { setQueryRequestedAt_DateHistogram("queryRequestedAt", opLambda, aggsLambda); }
Example #23
Source File: BsClickLogCA.java From fess with Apache License 2.0 | 4 votes |
public void setQueryRequestedAt_DateHistogram(ConditionOptionCall<DateHistogramAggregationBuilder> opLambda) { setQueryRequestedAt_DateHistogram("queryRequestedAt", opLambda, null); }
Example #24
Source File: BsUserInfoCA.java From fess with Apache License 2.0 | 4 votes |
public void setCreatedAt_DateHistogram(ConditionOptionCall<DateHistogramAggregationBuilder> opLambda, OperatorCall<BsUserInfoCA> aggsLambda) { setCreatedAt_DateHistogram("createdAt", opLambda, aggsLambda); }
Example #25
Source File: BsUserInfoCA.java From fess with Apache License 2.0 | 4 votes |
public void setUpdatedAt_DateHistogram(ConditionOptionCall<DateHistogramAggregationBuilder> opLambda, OperatorCall<BsUserInfoCA> aggsLambda) { setUpdatedAt_DateHistogram("updatedAt", opLambda, aggsLambda); }
Example #26
Source File: BsUserInfoCA.java From fess with Apache License 2.0 | 4 votes |
public void setUpdatedAt_DateHistogram(ConditionOptionCall<DateHistogramAggregationBuilder> opLambda) { setUpdatedAt_DateHistogram("updatedAt", opLambda, null); }