<dependency>
<groupId>io.github.snowthinker</groupId>
<artifactId>elasticsearch-helper</artifactId>
<version>0.0.2-RELEASE</version>
</dependency>
int pageSize = 10;
// 深度分页
Object[] searchAfters = new Object[]{"Iphone", "_id"};
// 排序必需和深度分页顺序相一致
SortBuilder[] orders = new SortBuilder[2];
orders[0] = SortBuilders.fieldSort("name.keyword").order(SortOrder.DESC);
orders[1] = SortBuilders.fieldSort("id.keyword").order(SortOrder.DESC);
// 条件查询
QueryBuilder queryBuilder = QueryBuilders.termQuery("name", "Iphone");
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withIndices("item")
.withQuery(queryBuilder)
.build();
Page<Item> pageResult = customElasticsearchTemplate.searchAfter(searchQuery, Arrays.asList(orders), searchAfters, pageSize, Item.class);
List<Item> dataList = pageResult.get().collect(Collectors.toList());
log.info("Total Record: {}, page list: {}", pageResult.getTotalElements(), dataList);
<logger name="org.springframework.data.elasticsearch.core.QUERY" level="DEBUG"/>