一、依赖

<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:9200
      username: elastic
      password: elastic

三、操作

 @Autowired
 private 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

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐