/**
* 高级检索(组合条件检索)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;
}