1. 程式人生 > >elasticsearch高級組合查詢ava

elasticsearch高級組合查詢ava

mod ear tran sys () else rep 字段 advance

/**
* 高級檢索(組合條件檢索)must相當於sql and操作
* @param modelType 0為模糊查詢,1為精確查詢
* @param index 索引
* @param map key為查詢字段和value為查詢內容
* @param Page 分頁頁碼
* @param Pagesize 每頁顯示條數
* @return SearchHits
*/
public static SearchHits AdvancedQuery1(Integer modelType,String index,Map<String,String> map,int Page,int Pagesize){
SearchRequestBuilder sr =transportClient.prepareSearch(index);
BoolQueryBuilder queryBuilder=QueryBuilders.boolQuery();
System.out.println(index);
if(modelType==0){
for(Map.Entry<String, String> entry : map.entrySet()){

//wildcardQuery 模糊查詢
queryBuilder.must(QueryBuilders.wildcardQuery(entry.getKey(), entry.getValue()+"*"));
}
}
else if(modelType==1){
for(Map.Entry<String, String> entry : map.entrySet()){

//termQuery 查詢精確
queryBuilder.must(QueryBuilders.termQuery(entry.getKey(),entry.getValue()));
}
}
sr.setQuery(queryBuilder)
.setFrom((Page-1)*Pagesize)
.setSize(Pagesize);
SearchResponse response=sr.get();
SearchHits hits=response.getHits();
return hits;

}

elasticsearch高級組合查詢ava