public void () throws IOException {
SearchRequest searchRequest = new SearchRequest("item");
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.matchQuery("scompCode", "G0000001"));
// 模糊查詢
boolQueryBuilder.filter(QueryBuilders.wildcardQuery("itemDesc", "*手機(jī)*"));
// 范圍查詢 from:相當(dāng)于閉區(qū)間; gt:相當(dāng)于開區(qū)間(>) gte:相當(dāng)于閉區(qū)間 (>=) lt:開區(qū)間(<) lte:閉區(qū)間 (<=)
boolQueryBuilder.filter(QueryBuilders.rangeQuery("itemPrice").from(4500).to(8899));
sourceBuilder.query(boolQueryBuilder);
searchRequest.source(sourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
logger.info("查詢數(shù)據(jù):{}", Arrays.toString(searchResponse.getHits().getHits()));
}
BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
boolBuilder.filter(QueryBuilders.termQuery("mobile", AppConfigConstants.MONTH_REPORT_TOTAL_USER));
sourceBuilder.query(boolBuilder);
SearchRequest searchRequest = new SearchRequest();
searchRequest.indices(AppConfigConstants.MONTH_REPORT_ES_INDEX);
searchRequest.source(sourceBuilder);
SearchResponse response = null;
try {
response = highLevelClient.search(searchRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
logger.error("[ElasticSearchService] countTotalUserNum error!", e);
throw new InsurfaceException(InsurfaceCodeEnum.ES_QUERY_ERROR);
}
BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
boolBuilder.filter(QueryBuilders.rangeQuery("num").gte(userPolicyNum));
sourceBuilder.query(boolBuilder);
CountRequest countRequest = new CountRequest();
countRequest.indices(AppConfigConstants.MONTH_REPORT_ES_INDEX);
countRequest.source(sourceBuilder);
CountResponse count = null;
try {
count = highLevelClient.count(countRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
logger.error("[ElasticSearchService] search error!", e);
throw new InsurfaceException(InsurfaceCodeEnum.ES_QUERY_ERROR);
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者