CardinalityAggregationBuilder cardinalityAggregation = AggregationBuilders.cardinality("custCard").field("customer_no.keyword");
//返回字段取最新一条记录
TopHitsAggregationBuilder topHitsAggregation = AggregationBuilders.topHits(“latestCust”)
.fetchSource(new String[]{“customer_no”, “customer_name”, “identify_no”, “visit_time”, “service_item_names”, “organization_name”, “id”, “type”} , null).size(1) .sort(“visit_time_long”, SortOrder.DESC);
//以会员编码分组
TermsAggregationBuilder termsAggregationBuilder = AggregationBuilders.terms(“topCustomer”).field(“customer_no.keyword”)
.size(pageNo.intValue() * pageSize.intValue())
.subAggregation(bucketSortAggregation)
.subAggregation(topHitsAggregation);
//es查询 分页指标和分组terms要同级
//hit查询返回0条数据
searchSourceBuilder.size(0);
searchSourceBuilder.from(0);
//排序
searchRequest.source(searchSourceBuilder.sort(“visit_time_long”, Sor