[英]Not able to connect with ElasticSearch 7.3.0 for logger dependency error in elasticSearch client
I'm running a simple method that will connect with elasticsearch and feed data to a particular index with the pom.xml 我正在运行一个简单的方法,该方法将与elasticsearch连接并使用pom.xml将数据馈送到特定索引
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.elasticsearch/elasticsearch -->
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.elasticsearch.client/transport -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>7.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Following is the code block that I have run 以下是我运行的代码块
package com.example.demo;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
public class Es {
public static void main(String[] args) {
try {
Client client = new PreBuiltTransportClient(Settings.builder().put("client.transport.sniff", true)
.put("client.transport.ignore_cluster_name", true).build())
.addTransportAddress(new TransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
String json = "{" + "\"user\":\"kimchy\"," + "\"postDate\":\"2013-01-30\","
+ "\"message\":\"trying out Elasticsearch\"" + "}";
IndexResponse response = client.prepareIndex("twitter", "_doc").setSource(json, XContentType.JSON).get();
// Index name
System.out.println(response.getIndex());
// Type name
System.out.println(response.getType());
// Document ID (generated or not)
System.out.println(response.getId());
// Version (if it's the first time you index this document, you will get: 1)
System.out.println(response.getVersion());
// status has stored current instance statement.
System.out.println(response.status());
client.close();
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
When i run the main method it will show the following error 当我运行main方法时,它将显示以下错误
Exception in thread "main" java.lang.NoSuchMethodError: 'org.apache.logging.log4j.Logger org.elasticsearch.common.logging.Loggers.getLogger(java.lang.String)'
at org.elasticsearch.transport.netty4.Netty4InternalESLogger.<init>(Netty4InternalESLogger.java:34)
at org.elasticsearch.transport.netty4.Netty4Utils$1.newInstance(Netty4Utils.java:53)
at io.netty.util.internal.logging.InternalLoggerFactory.getInstance(InternalLoggerFactory.java:93)
at io.netty.util.internal.logging.InternalLoggerFactory.getInstance(InternalLoggerFactory.java:86)
at io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:70)
at io.netty.util.ConstantPool.<init>(ConstantPool.java:32)
at io.netty.util.AttributeKey$1.<init>(AttributeKey.java:27)
at io.netty.util.AttributeKey.<clinit>(AttributeKey.java:27)
at org.elasticsearch.transport.netty4.Netty4Transport.<clinit>(Netty4Transport.java:231)
at org.elasticsearch.transport.Netty4Plugin.getSettings(Netty4Plugin.java:56)
at org.elasticsearch.plugins.PluginsService.lambda$getPluginSettings$0(PluginsService.java:89)
at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:271)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
at org.elasticsearch.plugins.PluginsService.getPluginSettings(PluginsService.java:89)
at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:156)
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:296)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:130)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:116)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:106)
at com.example.demo.Es.main(Es.java:20)
I am also changing the ElasticSearch client dependency version to 6.9 to 7.3 but getting the same error. 我也将ElasticSearch客户端依赖项版本更改为6.9到7.3,但收到相同的错误。
Changing the logger dependency to 将记录器依赖项更改为
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
instead of using log4j-to-slf4j, slf4j-api & logback-classic 而不是使用log4j-to-slf4j,slf4j-api和logback-classic
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.