当前位置:网站首页>es使用collapseBuilder去重和只返回某个字段

es使用collapseBuilder去重和只返回某个字段

2022-07-05 01:15:00 talen_hx296

去重  

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)

原网站

版权声明
本文为[talen_hx296]所创,转载请带上原文链接,感谢
https://blog.csdn.net/talen_hx/article/details/125508724

随机推荐