看完这篇文章,你会知道以下内容
环境 es5.6.8 springboot2.0.1
如何使用java客户端对es进行相关增删改查操作
导入依赖
其中transport是与es发送请求的客户端,还有一些关于日志的,jackson是用来将对象和json互相转换的工具
< dependencies>
< dependency>
< groupId> org. elasticsearch< / groupId>
< artifactId> elasticsearch< / artifactId>
< version> 5.6 .8 < / version>
< / dependency>
< dependency>
< groupId> org. elasticsearch. client< / groupId>
< artifactId> transport< / artifactId>
< version> 5.6 .8 < / version>
< / dependency>
< dependency>
< groupId> org. apache. logging. log4j< / groupId>
< artifactId> log4j- to- slf4j< / artifactId>
< version> 2.9 .1 < / version>
< / dependency>
< dependency>
< groupId> org. slf4j< / groupId>
< artifactId> slf4j- api< / artifactId>
< version> 1.7 .24 < / version>
< / dependency>
< dependency>
< groupId> org. slf4j< / groupId>
< artifactId> slf4j- simple< / artifactId>
< version> 1.7 .21 < / version>
< / dependency>
< dependency>
< groupId> log4j< / groupId>
< artifactId> log4j< / artifactId>
< version> 1.2 .12 < / version>
< / dependency>
< dependency>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< version> 4.12 < / version>
< / dependency>
< dependency>
< groupId> com. fasterxml. jackson. core< / groupId>
< artifactId> jackson- core< / artifactId>
< version> 2.8 .7 < / version>
< / dependency>
< dependency>
< groupId> com. fasterxml. jackson. core< / groupId>
< artifactId> jackson- databind< / artifactId>
< version> 2.8 .7 < / version>
< / dependency>
< dependency>
< groupId> com. fasterxml. jackson. core< / groupId>
< artifactId> jackson- annotations< / artifactId>
< version> 2.8 .1 < / version>
< / dependency>
< / dependencies>
public class Article {
private Long id;
private String title;
public Article ( ) {
}
@Override
public String toString ( ) {
return "Article{" +
"id=" + id +
", title='" + title + '\'' +
'}' ;
}
public Long getId ( ) {
return id;
}
public void setId ( Long id) {
this. id = id;
}
public String getTitle ( )<