> 文章列表 > springboot集成ElasticSearch(支持集群)

springboot集成ElasticSearch(支持集群)

springboot集成ElasticSearch(支持集群)

一、依赖

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>

二、配置文件

spring:elasticsearch:rest:
#      uris、username和password项需要填写协调节点服务地址(IP地址+端口号)、用户名和密码。当有多个协调节点时,可以设置uris的值为多个协调节点的服务地址,中间用逗号分隔uris: http://localhost:9200username: elasticpassword: elastic

三、操作

 @Autowiredprivate ElasticsearchRestTemplate elasticsearchRestTemplate;
#判断索引是否存在
restTemplate.indexExists(indexName)
#创建索引
restTemplate.createIndex(indexName); 
#创建表结构
restTemplate.putMapping(xxxx.class);
#写入数据到制定索引
restTemplate.save(item, IndexCoordinates.of(indexName));

更多操作可参考

https://blog.csdn.net/feiying0canglang/article/details/120706299