使用环境:IDEA、Maven
创建maven工程进行API的使用
pom依赖:
<dependencies>
<!-- junit是单元测试的使用 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- ElasticSearch需要的依赖 -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>6.1.1</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>6.1.1</version>
</dependency>
<!-- ElasticSearch需要的log4j -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.9.1</version>
</dependency>
</dependencies>
注意:完成上述操作后既可以正常编写ElasticSearchAPI了,运行的时候会出现以下异常
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'log4j2.debug' to show Log4j2 internal initialization logging.
出现该异常的原因:缺少ElasticSearch的log4j2.properties文件。
解决方法:在maven工程的resources目录中新建一个文件命名为“log4j2.properties”,文件中添加以下内容
appender.console.type = Console
appender.console.name = console
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %marker%m%n
rootLogger.level = info
rootLogger.appenderRef.console.ref = console
如此ElasticSearch6.X的JavaAPI环境部署成功!
Linux部署ElasticSearch集群:安装Elasticsearch及其遇到的坑
ElasticSearch的Chrome的插件安装:安装elasticsearch-head.crx插件