elasticsearch
ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索引擎。设计用于[云计算]中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。
spring boot操作elasticsearch需要通过spring data elasticsearch来实现
添加依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
实现效果:

实体类:
package com.example.demo.entity;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
/**
* Created by linziyu on 2018/5/19.
* 实体类
*
*
*/
//定义索引名字及类型
@Document(indexName = "poem",type = "poem",shards = 1, replicas = 0)
public class Poem {
@Id
private long id;
private String title;
private String content;
public Poem(long id, String title, String content) {
this.id = id;
this.title = title;
this.content = content;
}
public Poem(String title, String content) {
this.title = title;
this.content = content;
}
public Poem() {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {

本文介绍了如何使用Spring Boot与Elasticsearch结合,实现简单的全文搜索功能。通过添加依赖,设置配置,创建实体类,实现ElasticsearchRepository接口,以及编写必要的业务逻辑,可以实现对Elasticsearch的CRUD操作。在运行示例前,需要确保本地Elasticsearch服务已启动。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



