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;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)