Elaticsearch客户端
小于 1 分钟
java客户端
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.10.2</version>
</dependency>
Spring Data ElasticSearch
官方网站:http://projects.spring.io/spring-data-elasticsearch
的ElasticSearch的版本是7.10.2,以推荐使用Springboot的版本应该是2.3以上版本,并且在配置文件中声明使用的ES版本
- 依赖jar包
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/>
</parent>
<properties>
<!--告诉springboot我们处理的ES的版本-->
<elasticsearch.version>7.10.2</elasticsearch.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
</dependencies>
- 配置文件
spring:
elasticsearch:
rest:
uris:
- 192.16.18.101:9200
- 192.16.18.102:9200
- 192.16.18.103:9200
- 索引创建
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
@Data
@Document(indexName = "blog_1", shards = 5, replicas = 1)
public class Blog {
@Id
@Field(type = FieldType.Long, store = true)
private Long id;
@Field(type = FieldType.Text, analyzer = "ik_max_word", store = true)
private String title;
@Field(type = FieldType.Text, analyzer = "ik_max_word", store = true)
private String content;
@Field(type = FieldType.Text, analyzer = "ik_max_word", store = true)
private String comment;
@Field(type = FieldType.Keyword, store = true)
private String mobile;
}