In “spring-data-elasticsearch” 4.0.4.RELEASE, how to convert SearchHits to Page?

前提是你 提交于 2021-01-28 08:45:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!