gpt4 book ai didi

java - ElasticSearch 给出 ReceiveTimeoutTransportException

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

您好,我正在尝试将我的 ElasticSearch 客户端连接到我的本地主机并尝试从那里获取索引。

import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.node.Node;
import org.elasticsearch.client.transport.*;
import org.elasticsearch.common.transport.*;
import java.io.IOException;
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
public class ESClient
{
public static void search()throws IOException
{
Node node;
node = nodeBuilder().clusterName("elasticsearch").node();
Client client;
client= new TransportClient()
.addTransportAddress(new InetSocketTransportAddress("localhost", 9200));
GetResponse response;
response= client.prepareGet("twitter", "tweet", "1").execute() .actionGet();
System.out.println(response.toString());

}
public static void main(String args[])throws IOException
{
search();

}

}

我已经使用终端创建了索引。

curl -XPUT 'http://localhost:9200/twitter/' curl -XPUT 'http://localhost:9200/twitter/_mapping/tweet' -d ' {
"tweet" : { "properties" : {
"message" : {"type" : "string", "store" : true } }
} } '

当我执行它时,抛出以下错误,

NFO: [Blackheath] failed to get node info for [#transport#-1][BLRMCB-C02L56J4DR53.local][inet[localhost/127.0.0.1:9200]], disconnecting... org.elasticsearch.transport.ReceiveTimeoutTransportException: [][inet[localhost/127.0.0.1:9200]][cluster:monitor/nodes/info] request_id [0] timed out after [5002ms] at org.elasticsearch.transport.TransportService$TimeoutHandler.run(TransportService.java:366) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

Exception in thread "main" org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [] at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:278) at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:197) at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:106) at org.elasticsearch.client.support.AbstractClient.get(AbstractClient.java:193) at org.elasticsearch.client.transport.TransportClient.get(TransportClient.java:384) at org.elasticsearch.action.get.GetRequestBuilder.doExecute(GetRequestBuilder.java:201) at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:91) at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65) at ....ESClient.search(ESClient.java:30) at ....ESClient.main(ESClient.java:36) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

这是什么问题,谁能告诉我?

最佳答案

当我从使用 ElasticSearchAdapter 进行查询切换到使用 SparkStreamingAdapter 进行相同查询时,我遇到了这个错误。我不得不将端口更改为9300,然后就没有出现这个错误。

这个问题/答案帮助我解决了这个问题: Why can't I connect to ElasticSearch through Java API?

关于java - ElasticSearch 给出 ReceiveTimeoutTransportException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30342922/

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