/**
* es全文检索java实现API
* @author zxy
*
*/
public class EsPersonDao {
/**
*
* @param index 查询的索引
* @param str 查询内容
* @param Page 页码
* @param Pagesize 每页显示条数
* @return SearchHits, json结构的结果集
*/
public SearchHits FullTextQuery(String index,String str,int Page,int Pagesize){
//transportClient 为连接es集群的Client
SearchRequestBuilder sr =transportClient.prepareSearch(index);
//query方式查询,条件为“all”,指所有可查询的field
QueryBuilder queryBuilder=QueryBuilders.matchPhraseQuery("_all", str);
sr.setQuery(queryBuilder)
.setFrom((Page-1)*Pagesize)
.setSize(Pagesize)
.execute()
.actionGet();
//执行查询
SearchResponse response=sr.get();
//返回查询
SearchHits hits=response.getHits();
return hits;
}
}