ES java 根据条件查询总数
public long countSearch(String index,Map<String,Object> paramMap,Map<String, Object> notParamMap,String startTime,String endTime,String fuzzySearchStr) throws IOException {CountRequest cou
·
public long countSearch(String index,String fuzzySearchStr) throws IOException {
CountRequest countRequest = new CountRequest(index);
SearchSourceBuilder builder = new SearchSourceBuilder();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
//等于条件
boolQueryBuilder.must(QueryBuilders.termsQuery("字段" + ".keyword", "字段值"));
//不等于条件
boolQueryBuilder.mustNot(QueryBuilders.termsQuery("字段" + ".keyword", "字段值"));
//时间范围查询
boolQueryBuilder.must(QueryBuilders.rangeQuery("字段"+ ".keyword").from("开始时间值"));
boolQueryBuilder.must(QueryBuilders.rangeQuery("字段"+ ".keyword").to("结束时间值"));
//全局模糊查询
if (StringUtils.isNotBlank(fuzzySearchStr)) {
boolQueryBuilder.must(QueryBuilders.queryStringQuery("*"+fuzzySearchStr+"*"));
}
builder.query(boolQueryBuilder);
countRequest.source(builder);
CountResponse countResponse = client.count(countRequest, RequestOptions.DEFAULT);
long count = countResponse.getCount();
return count;
}
更多推荐
已为社区贡献5条内容
所有评论(0)