Springboot整合Elasticsearch新版分页查询
其它插入、删除、简单查询都可以通过Repository调用方法查询。
分页查询
Elasticsearch现在的新版本已经弃用了ElasticsearchTemplate类,Repository里原来的search方法也已经弃用了。下面是使用ElasticsearchRestTemplate类实现的分页查询
代码
package com.lzl.community;
import com.lzl.community.entity.DiscussPost;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.*;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
import org.springframework.data.elasticsearch.core.query