distinctFieldName 就是去重字段,这个字段必须是keyword类型 不然会报错
//指定去重字段 CollapseBuilder collapseBuilder = new CollapseBuilder(distinctFieldName); // 查询去重后的结果数量 CardinalityAggregationBuilder aggregationBuilder = AggregationBuilders.cardinality("distinct").field(distinctFieldName); sourceBuilder.collapse(collapseBuilder); sourceBuilder.aggregation(aggregationBuilder);
//去重查询要取另外的总数量 ParsedCardinality distinct = search.getAggregations().get("distinct"); Long total = NumberUtil.parseLong(distinct.getValueAsString());
SpringBoot 整合es(elasticsearch)使用elasticsearch-rest-high-level-client实现增删改查参考:https://www.cnblogs.com/pxblog/p/14808454.html
标签:collapseBuilder,distinct,distinctFieldName,查询,字段,elasticsearch,es From: https://www.cnblogs.com/pxblog/p/17048864.html