今天咱们就来聊一聊elasticsearch8.x版本如何设置搜索关键词高亮并且分页,因为es7.x和es8.x版本差异比较大,导致了很多es用户在使用时出现了很多问题,es7和es8的高亮就非常不一样,话不多说,直接上代码解释。
如果大家遇到了版本问题或者Java连接不上elasticsearch8.x,可以查看我的这一篇博客elasticsearch 8.7.0的Java API详解教程(一)_不败顽童博主的博客-CSDN博客
@Service
@Slf4j
public class ArticleServiceImpl implements IArticleService {
@Autowired
private ElasticSearchArticleMapper elasticSearchArticleMapper;
@Autowired
private ElasticsearchClient elasticsearchClient;
@Autowired
private KeyWordApi keywordApi;
@Transactional(rollbackFor = Exception.class)
@Override
public Page search(PageQueryParam pageQueryParam) {
//根据一个值查询多个字段 并高亮显示 这里的查询是取并集,即多个字段只需要有一个字段满足即可
//需要查询的字段
List result = new ArrayList();
SearchResponse
当中page分页是作者自己编写的一个简单的分页
@Data
public class Page {
/**
* 当前页数
*/
private Integer pageNum = 1;
/**
* 当前显示行数
*/
private Integer pageSize = 10;
/**
* 总页数
*/
private Long totalPages = 0L;
/**
* 总行数
*/
private Long totalCount = 0L;
/**
* 是否为最后一页
*/
private boolean last = false;
/**
* 判断第一页
*/
private boolean first = true;
private List rows = new ArrayList();
}
下面是article索引实体类
@Data
@Document(indexName = "article")
public class ArticleIndex {
private static final long serialVersionUID = 132913819042348092L;
/**
* 主键
*/
@Id
private Long id;
/**
* 作者
*/
@Field(store = true, type = FieldType.Keyword)
private Long userId;
/**
* 文章標題
*/
@Field(store = true, type = FieldType.Text, analyzer = "ik_smart")
private String title;
/**
* 英文文章標題
*/
@Field(store = true, type = FieldType.Text, analyzer = "ik_smart")
private String titleEn;
/**
* 文章原始详情
*/
@Field(store = true, type = FieldType.Text, analyzer = "ik_smart")
private String plainTextBody;
/**
* 會員限定
*/
@Field(store = true, type = FieldType.Keyword)
private Boolean memberOnly;
/**
* 申請首頁輪播圖
*/
@Field(store = true, type = FieldType.Keyword)
private Boolean applyHomepageCarousel;
/**
*
*/
@Field(store = true, type = FieldType.Text, analyzer = "ik_smart")
private String ogTitle;
/**
* SEO用的主前綴
*/
@Field(store = true, type = FieldType.Text, analyzer = "ik_smart")
private String parentPath;
/**
* SEO用的副前綴
*/
@Field(store = true, type = FieldType.Text, analyzer = "ik_smart")
private String childPath;
/**
*
*/
@Field(store = true, type = FieldType.Keyword)
private String slug;
/**
* 點擊數
*/
@Field(store = true, type = FieldType.Keyword)
private Long clicksCount;
/**
* 留言數
*/
@Field(store = true, type = FieldType.Keyword)
private Object commentsCount;
/**
* 完成文章時間 (待審核)
*/
@Field(index = false, store = true, type = FieldType.Date, format = DateFormat.date_optional_time,ignoreMalformed = true)
private Date completedAt;
/**
* 通過審核時間
*/
@Field(index = false, store = true, type = FieldType.Date, format = DateFormat.date_optional_time,ignoreMalformed = true)
private Date verifiedAt;
/**
* 發佈時間
*/
@Field(index = false, store = true, type = FieldType.Date, format = DateFormat.date_optional_time,ignoreMalformed = true)
private Date publishedAt;
/**
* 下架時間
*/
@Field(index = false, store = true, type = FieldType.Date, format = DateFormat.date_optional_time,ignoreMalformed = true)
private Date expiredAt;
/**
* 刪除時間
*/
@Field(index = false, store = true, type = FieldType.Date, format = DateFormat.date_optional_time,ignoreMalformed = true)
private Date deletedAt;
/**
*
*/
@Field(index = false, store = true, type = FieldType.Date, format = DateFormat.date_optional_time,ignoreMalformed = true)
private Date createdAt;
/**
*
*/
@Field(index = false, store = true, type = FieldType.Date, format = DateFormat.date_optional_time,ignoreMalformed = true)
private Date updatedAt;
/**
* 註冊人數
*/
@Field(store = true, type = FieldType.Keyword)
private Long viaCount;
/**
* 特派員
*/
@Field(store = true, type = FieldType.Keyword)
private Long reporterId;
/**
* 預覽密碼
*/
@Field(store = false, type = FieldType.Keyword)
private String previewPasscode;
/**
* 內容摘要
*/
@Field(store = true, type = FieldType.Text, analyzer = "ik_smart")
private String summary;
/**
* Optimistic Lock
*/
@Field(store = false, type = FieldType.Keyword)
private Object lockVersion;
/**
* 作者
*/
@Field(store = true, type = FieldType.Keyword)
private String authorName;
/**
* author_url
*/
@Field(store = true, type = FieldType.Keyword)
private String authorUrl;
/**
* categories
*/
@Field(store = true, type = FieldType.Keyword)
private String categories;
/**
* json格式类别
*/
@Field(store = true, type = FieldType.Object)
private List category;
/**
* 图片链接
*/
@Field(store = true)
private String imageUrl;
/**
* 类型
*/
@Field(store = tru服务器托管网e, type = FieldType.Keyword)
private String type;
}
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
想要制作这么一个简单的 3D 导航栏需要了解以下几个知识 : 1.空间转换 : 从坐标轴角度除了我们熟知的 X , Y 外还会和 Z 坐标轴 构成一个立体空间, Z轴的位置与我们眼睛视线的方向相同. 空间转换的属性仍然是 transform ,所以可以给他…