目录
官网API介绍
Java API Client
https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/index.html
Java REST Client(rest-high-level-client):
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high.html
Java REST Client依赖
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
</dependency>
使用对象操作es
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(
new HttpHost("localhost", 9200, "http")));
操作完后关闭连接
client.close();
1、新建maven项目
测试springboot集成elasticsearch的API使用
在新项目的pom文件中添加依赖
<!--导入了elasticsearch依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<!-- 引入fastjson依赖,发送elasticsearch的请求体时需要将对象转化为json字符串-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.62</version>
</dependency>
<!--引入lombok插件依赖,生成实体类的get、set等方法-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!--引入springboot测试依赖-->
<dependen