es使用collapseBuilder去重和只返回某个字段
去重指定字段
·
去重
SearchRequest searchRequest = new SearchRequest(esIndices2.toArray(new String[esIndices2.size()]));
// 构建搜索条件
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
//指定去重字段
CollapseBuilder collapseBuilder = new CollapseBuilder("userName.keyword");
searchRequest.source(sourceBuilder.query(boolBuilder).collapse(collapseBuilder).trackTotalHits(true));
指定字段
earchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.fetchSource("userName", null)
更多推荐
已为社区贡献5条内容
所有评论(0)