gpt4 book ai didi

java - 使用 Java 进行 Elasticsearch

转载 作者:搜寻专家 更新时间:2023-11-01 02:37:49 25 4
gpt4 key购买 nike

我正在尝试像这样连接到 Elastic Search,

Transport client = new PreBuiltTransportClient(Settings.EMPTY).
addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9200));

但是当我运行时出现以下错误:-

Exception in thread "main" java.lang.AbstractMethodError: io.netty.util.concurrent.MultithreadEventExecutorGroup.newChild(Ljava/util/concurrent/Executor;[Ljava/lang/Object;)Lio/netty/util/concurrent/EventExecutor;
at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:84)
at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:58)
at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:47)
at io.netty.channel.MultithreadEventLoopGroup.<init>(MultithreadEventLoopGroup.java:49)

我的pom.xml是

<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.6.2</version>
</dependency>

请帮忙提前谢谢

最佳答案

我猜这可能是因为在将 Elastic Search 的版本从低于 2.4 的版本升级到最新版本方面,您的实现发生了变化。

使用 current version 实现上述内容的正确方法会是——

TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9200));

虽然在Version 2.3之前和之前实现是:

Client client = TransportClient.builder().build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300));

我将按照 AbstractMethodError here 的定义进行操作

Thrown when an application tries to call an abstract method. Normally, this error is caught by the compiler; this error can only occur at run time if the definition of some class has incompatibly changed since the currently executing method was last compiled.

为此,我还建议您通过 mvn dependency:treeexclude 工件 org.elasticsearch.client< 的任何其他依赖项.

关于java - 使用 Java 进行 Elasticsearch ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42604757/

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