gpt4 book ai didi

maven - 由于elasticSearch客户端中的记录器依赖错误,无法与ElasticSearch 7.3.0连接

转载 作者:行者123 更新时间:2023-12-02 01:26:23 25 4
gpt4 key购买 nike

我正在运行一个简单的方法,该方法将与 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>

以下是我运行的代码块

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();
}
}
}

当我运行 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)

我还将 ElasticSearch 客户端依赖项版本更改为 6.9 到 7.3,但遇到了相同的错误。

最佳答案

将记录器依赖项更改为

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>

而不是使用 log4j-to-slf4j、slf4j-api 和 logback-classic

关于maven - 由于elasticSearch客户端中的记录器依赖错误,无法与ElasticSearch 7.3.0连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57582022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com