本篇文章代码实现不多,主要是教你如何用JestClient去实现ElasticSearch上的操作。
授人以鱼不如授人以渔。
一、说明
1、elasticsearch版本:6.2.4 。
jdk版本:1.8(该升级赶紧升级吧,现在很多技术都是最低要求1.8)。
jest版本:5.3.3。
2、一些不错的文章
一些基本概念的讲解:http://www.gaowm.com/categories/Elasticsearch/
es配置文件参数介绍:https://www.jianshu.com/p/149a8da90bbc
中文ik插件安装:https://blog.csdn.net/zjcjava/article/details/78653753
linux启动需要更改的一些参数:https://www.cnblogs.com/woxpp/p/6061073.html
二、前提:
1、最好已经大概看过es的官方文档,附上文档地址:
中文:https://www.elastic.co/guide/cn/elasticsearch/guide/cn/index.html 虽然已经有点老了,不过还是可以看看的。(我英文不好看的这个)
英文:https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html 英文好的直接看英文版的,毕竟是最新的。
2、知道自己需要的es命令:
比如想用jest进行索引模版的相关操作,需要知道操作模版的命令是“template” 等等。然后能在官方文档里查到相关命令的详细操作。
简单说就是现在已经知道怎么在 es里进行相关操作了。现在想要用jest进行实现。
三、开始:
1、pom依赖:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>ceshi</groupId> <artifactId>ceshi</artifactId> <version>0.0.1-SNAPSHOT</version> <dependencies> <dependency> <groupId>io.searchbox</groupId> <artifactId>jest</artifactId> <version>5.3.3</version> </dependency> <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>6.2.4</version> </dependency> </dependencies> <build> <plugins> <!-- java编译插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build> </project>
2、jest初始化,这里就不说了。直接开始操作了,简单说几个命令抛砖引玉:
索引模版:es命令地址:https://www.elastic.co/guide/cn/elasticsearch/guide/cn/index-templates.html
文档中可以看到命令是“_template”。
现在在jest的jar包里找 “template”相关的类
其实写到这 大概应该知道啥意思了。补张图:
写的有点乱,以后整理吧。