elasticsearch分页查询数据restful api以及java代码实现

restful api实现如下:

POST http://192.168.1.111:9200/film/dongzuo/_search/
{
  "from": 0,
  "size": 2
}

java es分页组件 es分页查询java_Nancy

返回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...