我的数据库中有重复的 id,并希望获得仅类似于 SQL 中的 SELECT COUNT(DISTINCT column) FROM table 的不同值的计数。public SearchSourceBuilder createQueryForCount(QueryBuilder queryBuilder, int start, boolean fetchSource, String field){ logger.info("Creating aggregation count "); QueryBuilder finalQuery = QueryBuilders.boolQuery().must(queryBuilder); AggregationBuilder aggregationCount = AggregationBuilders.terms("agg").field(USER_ID) .subAggregation(AggregationBuilders.topHits("top").explain(false).from(start)) .subAggregation(AggregationBuilders.count("count").field(field)); return new SearchSourceBuilder() .query(finalQuery) .fetchSource(fetchSource) .from(start) .aggregation(aggregationCount); }有没有办法在弹性搜索中进行不同的计数?
添加回答
举报
0/150
提交
取消