问题
In spring-data-elasticsearch
4.0.4.RELEASE, ElasticsearchRestTemplate
's queryForPage()
methods are deprecated, need to use search()
instead, which return SearchHits
instead of Page
.
So, how to convert SearchHits
to Page
, or how to still get results as Page
?
I have searched via google, and checked official doc, and checked source code, still don't know the best way, any help?
回答1:
The Query
parameter to be passed into the search()
method can have a Pageable
set for the request. To wrap the returned SearchHits<T>
object in a SearchPage<T>
you just can do
SearchPage<T> searchPage = SearchHitSupport.searchPageFor(searchHits, query.getPageable());
来源:https://stackoverflow.com/questions/64346398/in-spring-data-elasticsearch-4-0-4-release-how-to-convert-searchhits-to-page