分页+排序
@Test
public void contextLoads(){
//queryForPage()需要两个参数,通过Builder创建所需要的对象
FieldSortBuilder sort = SortBuilders.fieldSort("age").order(SortOrder.ASC);
NativeSearchQuery search = new NativeSearchQueryBuilder()
.withIndices("ems")
.withTypes("emp")
.withSort(sort)
.withPageable(PageRequest.of(0,5))
.build();
AggregatedPage<Emp> emps = elasticsearchTemplate.queryForPage(search, Emp.class);
emps.forEach(emp -> System.out.println(emp));
}
SearchResponse(原始响应的结果)
{
"took": 154,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 6,
"max_score": null,
"hits": [
{
"_index": "ems",
"_type": "emp",
"_id": "iKe8iXIBcEPuXohzqmGn",
"_score": null,
"_source": {
"name": "张小五",
"age": 8,
"bir": "2012-12-12",
"content": "Spring Cloud 作为Java 语言的微服务框架,它依赖于Spring Boot,有快速开发、持续交付和容易部署等特点。Spring Cloud 的组件非常多,涉及微服务的方方面面,井在开源社区Spring 和Netflix 、Pivotal 两大公司的推动下越来越完善",
"address": "无锡"
},
&#