Spring Boot集成ElasticSearch,
下载ElasticSearch
下载地址 https://www.elastic.co/downloads/past-releases
Spring Boot集成ElasticSearch(gradle)
// 添加 Spring Data Elasticsearch 的依赖
compile('org.springframework.boot:spring-boot-starter-data-elasticsearch')
// 添加 JNA 的依赖
compile('net.java.dev.jna:jna:4.3.0')
版本问题解决
application.properties
# Elasticsearch服务地址
spring.data.elasticsearch.cluster-nodes=localhost:9300
# 设置连接超时时间
spring.data.elasticsearch.properties.transport.tcp.connect_timeout=120s
定义索引实体类
org.springframework.data.elasticsearch.annotations.Document
类名上加@Document(indexName = "索引库名称" , type = "索引库类型")注解
org.springframework.data.annotation.Id
定义一个主键字段加@Id注解 索引ID , 类型为String
查询方法使用
自定义接口继承ElasticsearchRepository<索引实体类,String>
ElasticSearch具体用法
这个大神写的很详细了
https://www.cnblogs.com/guozp/archive/2018/04/02/8686904.html
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。