问题描述
在spring-data-elasticsearch
4.0.4.RELEASE中,ElasticsearchRestTemplate
的queryForPage()
方法被弃用,需要使用search()
代替,它返回 SearchHits
而不是 Page
.
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
.
那么,如何将SearchHits
转换为Page
,或者如何仍然获得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?
推荐答案
要传递到 search()
方法中的 Query
参数可以有一个 Pageable
为请求设置.要将返回的 SearchHits
对象包装在 SearchPage
中,您只需执行
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());
这篇关于在“spring-data-elasticsearch"中4.0.4.RELEASE,如何将SearchHits 转换为Page?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!