elasticsearch分页查询数据restful api以及java代码实现
restful api实现如下:
{
"from": 0,
"size": 2
}
返回2条数据
java代码实现如下:
/**
* 分页查询
* @throws Exception
*/
@Test
public void searchPaging()throws Exception{
SearchRequestBuilder srb=client.prepareSearch("film").setTypes("dongzuo");
SearchResponse sr=srb.setQuery(QueryBuilders.matchAllQuery()).setFrom(1).setSize(2).execute().actionGet(); // 查询所有
SearchHits hits=sr.getHits();
for(SearchHit hit:hits){
System.out.println(hit.getSourceAsString());
}
}
运行如下:
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...