gpt4 book ai didi

Java Elasticsearch 客户端 : throws ConnectException when connecting from local to ES in Google Cloud VM

转载 作者:太空宇宙 更新时间:2023-11-04 12:51:52 27 4
gpt4 key购买 nike

我有一个在 google-compute-engine(VM) 中运行的 elasticsearch 集群,并且我正在尝试从我的 Java 程序进行连接。

谷歌云中的ES实例有一个外部IP和内部IP。我已经配置了用于连接的外部 IP,并且所有防火墙设置都已启用以进行连接。

仍然看起来,客户端在将 myd 数据写入 ES 时正在使用内部 IP。

10.240.0.237是内部IP

Caused by: java.net.ConnectException: Connection timed out: no further information: /10.240.0.237:9300
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
at org.elasticsearch.common.netty.channel.socket.nio.NioClientBoss.connect(NioClientBoss.java:152)
at org.elasticsearch.common.netty.channel.socket.nio.NioClientBoss.processSelectedKeys(NioClientBoss.java:105)
at org.elasticsearch.common.netty.channel.socket.nio.NioClientBoss.process(NioClientBoss.java:79)
at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337)
at org.elasticsearch.common.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:42)
at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)

代码

public class ESClient {
final static Node[] esNodes = new Node[1];
static String indexName = "sa-sonarshock-log";
public static Client getClient(){
if(esNodes[0] == null){
esNodes[0] = _setupNode();
}
return esNodes[0].client();
}
public static Node _setupNode(){
Settings settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", "es-tifc-retro-testing")
.put("http.enabled", false)
.put("transport.tcp.port", "9300-9400")
.put("discovery.zen.ping.multicast.enabled", false)
.put("discovery.zen.ping.unicast.hosts", "estifcretrotest-es-tifc-retro-testing-1-vm")
.build();

return nodeBuilder().settings(settings).client(true).node();
}
public static Map<String, Object> putJsonDocument(String title, String content, Date postDate,
String[] tags, String author){
Map<String, Object> jsonDocument = new HashMap<String, Object>();
jsonDocument.put("title", title);
jsonDocument.put("conten", content);
jsonDocument.put("postDate", postDate);
jsonDocument.put("tags", tags);
jsonDocument.put("author", author);
return jsonDocument;
}
public static void main(String[] args) {
Client esClient = getClient();
CreateIndexRequestBuilder createIndexRequestBuilder = esClient.admin().indices().prepareCreate(indexName);
createIndexRequestBuilder.execute().actionGet();
esClient.prepareIndex(indexName, "default", "1")
.setSource(putJsonDocument("ElasticSearch: Java API",
"ElasticSearch provides the Java API, all operations "
+ "can be executed asynchronously using a client object.",
new Date(),
new String[]{"elasticsearch"},
"Remis Haroon")).execute().actionGet();
esNodes[0].close();
}
}

最佳答案

看起来您正在端口 9300 上进行连接,但我认为您需要端口 9200。

关于Java Elasticsearch 客户端 : throws ConnectException when connecting from local to ES in Google Cloud VM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35746644/

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