当前位置: 首页 > 知识库问答 >
问题:

无法使用Java API连接到ElasticSearch服务器

章哲茂
2023-03-14
    null

...9200/_cluster/nodes

{
  "ok": true,
  "cluster_name": "test",
  "nodes": {
    "NLVBbJpJTZWefeI2kQt3Tg": {
      "name": "inventory_management",
      "transport_address": "inet[/127.0.0.1:9300]",
      "hostname": "devhost1",
      "version": "0.90.5",
      "http_address": "inet[/127.0.0.1:9200]"
    }
  }
}

...9200/_cluster/health?pretty=true

{
  "cluster_name" : "test",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 0,
  "active_shards" : 0,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0
}

Java代码:

Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "test").put("node.name", "inventory_management").build();
Client client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
IndexResponse response = client.prepareIndex("twitter", "tweet", "1").setSource(json).execute().actionGet();
org.elasticsearch.transport.NodeDisconnectedException: [][inet[localhost/127.0.0.1:9300]][/cluster/nodes/info]
org.elasticsearch.client.transport.NoNodeAvailableException: No node available
    at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:138)
    at org.elasticsearch.client.transport.support.InternalTransportClient.index(InternalTransportClient.java:124)
    at org.elasticsearch.client.transport.TransportClient.index(TransportClient.java:242)
    at org.elasticsearch.client.action.index.IndexRequestBuilder.doExecute(IndexRequestBuilder.java:219)
    at org.elasticsearch.client.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:52)
    at org.elasticsearch.client.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:47)
[2013-10-24 16:37:15,783][DEBUG][threadpool.cached        ] [Aragorn] Initializing cached thread pool with keep_alive[1m], scheduled_size[20]
[2013-10-24 16:37:15,809][DEBUG][client.transport         ] [Aragorn] node_sampler_interval[1s]
[2013-10-24 16:37:15,820][DEBUG][netty.channel.socket.nio.NioProviderMetadata] Using the autodetected NIO constraint level: 0
[2013-10-24 16:37:15,872][DEBUG][transport.netty          ] [Aragorn] Connected to node [[#temp#-1][inet[localhost/127.0.0.1:9300]]]
[2013-10-24 16:37:15,892][DEBUG][transport.netty          ] [Aragorn] Disconnected from [[#temp#-1][inet[localhost/127.0.0.1:9300]]]
[2013-10-24 16:37:15,894][DEBUG][client.transport         ] [Aragorn] Failed to get node info from [#temp#-1][inet[localhost/127.0.0.1:9300]], removed from nodes list
org.elasticsearch.transport.NodeDisconnectedException: [][inet[localhost/127.0.0.1:9300]][/cluster/nodes/info]
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: "localhost" # Tried with devhost1 127.0.0.1 as well and ["localhost"] too
[2013-10-25 13:49:58,379][INFO ][node                     ] [inventory_management] version[0.90.5], pid[2426], build[c8714e8/2013-09-17T12:50:20Z]
[2013-10-25 13:49:58,379][INFO ][node                     ] [inventory_management] initializing ...
[2013-10-25 13:49:58,382][INFO ][plugins                  ] [inventory_management] loaded [], sites []
[2013-10-25 13:49:59,853][INFO ][node                     ] [inventory_management] initialized
[2013-10-25 13:49:59,853][INFO ][node                     ] [inventory_management] starting ...
[2013-10-25 13:49:59,937][INFO ][transport                ] [inventory_management] bound_address {inet[/0:0:0:0:0:0:0:0:9300]}, publish_address {inet[/192.168.1.50:9300]}
[2013-10-25 13:50:02,960][INFO ][cluster.service          ] [inventory_management] new_master [inventory_management][2-uG1xVNSSiLo5RVRrjbGg][inet[/192.168.1.50:9300]], reason: zen-disco-join (elected_as_master)
[2013-10-25 13:50:02,972][INFO ][discovery                ] [inventory_management] test/2-uG1xVNSSiLo5RVRrjbGg
[2013-10-25 13:50:02,989][INFO ][http                     ] [inventory_management] bound_address {inet[/0:0:0:0:0:0:0:0:9200]}, publish_address {inet[/192.168.1.50:9200]}
[2013-10-25 13:50:02,989][INFO ][node                     ] [inventory_management] started
[2013-10-25 13:50:03,024][INFO ][gateway                  ] [inventory_management] recovered [0] indices into cluster_state
[2013-10-25 13:50:09,399][WARN ][transport.netty          ] [inventory_management] exception caught on transport layer [[id: 0x02649775, /127.0.0.1:50028 => /127.0.0.1:9300]], closing connection
java.io.StreamCorruptedException: invalid internal transport message format
    at org.elasticsearch.transport.netty.SizeHeaderFrameDecoder.decode(SizeHeaderFrameDecoder.java:27)
    at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:425)
    at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303)
    at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
    at org.elasticsearch.common.netty.OpenChannelsHandler.handleUpstream(OpenChannelsHandler.java:74)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
    at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:268)
    at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:255)
    at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
    at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:109)
    at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:312)
    at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:90)
    at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
    at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
    at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
[2013-10-25 13:50:09,403][WARN ][transport.netty          ] [inventory_management] exception caught on transport layer [[id: 0x02649775, /127.0.0.1:50028 :> /127.0.0.1:9300]], closing connection
java.io.StreamCorruptedException: invalid internal transport message format
    at org.elasticsearch.transport.netty.SizeHeaderFrameDecoder.decode(SizeHeaderFrameDecoder.java:27)
    at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:425)
    at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.cleanup(FrameDecoder.java:482)
    at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.channelDisconnected(FrameDecoder.java:365)
    at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:102)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
    at org.elasticsearch.common.netty.OpenChannelsHandler.handleUpstream(OpenChannelsHandler.java:74)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
    at org.elasticsearch.common.netty.channel.Channels.fireChannelDisconnected(Channels.java:396)
    at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.close(AbstractNioWorker.java:361)
    at org.elasticsearch.common.netty.channel.socket.nio.NioServerSocketPipelineSink.handleAcceptedSocket(NioServerSocketPipelineSink.java:81)
    at org.elasticsearch.common.netty.channel.socket.nio.NioServerSocketPipelineSink.eventSunk(NioServerSocketPipelineSink.java:36)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendDownstream(DefaultChannelPipeline.java:574)
    at org.elasticsearch.common.netty.channel.Channels.close(Channels.java:812)
    at org.elasticsearch.common.netty.channel.AbstractChannel.close(AbstractChannel.java:197)
    at org.elasticsearch.transport.netty.NettyTransport.exceptionCaught(NettyTransport.java:501)
    at org.elasticsearch.transport.netty.MessageChannelHandler.exceptionCaught(MessageChannelHandler.java:228)
    at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:112)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
    at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.exceptionCaught(FrameDecoder.java:377)
    at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:112)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
    at org.elasticsearch.common.netty.OpenChannelsHandler.handleUpstream(OpenChannelsHandler.java:74)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
    at org.elasticsearch.common.netty.channel.Channels.fireExceptionCaught(Channels.java:525)
    at org.elasticsearch.common.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:48)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.notifyHandlerException(DefaultChannelPipeline.java:658)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:566)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
    at org.elasticsearch.common.netty.OpenChannelsHandler.handleUpstream(OpenChannelsHandler.java:74)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
    at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:268)
    at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:255)
    at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
    at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:109)
    at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:312)
    at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:90)
    at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
    at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
    at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)

+++++++++++++++++++++++
+++++++++++++++++++++++

Java版本:

java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.12) (7u25-2.3.12-4ubuntu3)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

+++++++++++++++++++++++
+++++++++++++++++++++++
+++++++++++++++++++++++

问题已按以下方式解决。确保您的客户端和服务器版本是同步的!

共有1个答案

姜聪
2023-03-14

因此,这个问题被标记为回答可能遇到同样问题的其他人(答案实际上在问题的末尾)。

我遇到了同样的问题,结果是Java客户机使用的JAR版本和服务器运行的版本之间存在差异。你最好的办法是确保一个精确的匹配,然后这里给出的指示只是工作W/O任何调整。

另一件需要检查的事情是Java客户机是否使用了正确的端口,而不是http客户机使用的端口。正确的端口默认为9300而不是后者使用的9200。

 类似资料:
  • 误差 ...9200/_nodes Java代码: 更新: 我在ElasticSearch.yml中所做的更改 https://host:9200/_cluster/health?pretty=true的结果

  • 我的elasticsearch服务器运行时有索引,比如说服务器XX。XXX。XXX。XXX:9200。 我在服务器ES集群XX中有索引。XXX。XXX。XXX:9200,我正试图在本地主机5601(Kibana)中为其创建仪表盘 在我的kibana.yml我有这样的配置: 在弹性搜索中。yml我有这个配置: 但我在运行kibana时遇到了这个错误。yml: 连接ECONNREFUSED超文本传输协

  • 这是mysql连接php脚本。它不断地显示出它的错误 警告:mysqli_connect():(HY000/1045):用户'user'@'localhost'(使用密码:YES)在第6行的C:\xampp\htdocs\index.php访问被拒绝 注意:尝试在第7行连接成功的C:\xampp\htdocs\index.php中获取非对象的属性 我听不懂,请帮帮我好吗?

  • 首先,我知道有很多类似的问题,但我所看到的似乎都不能解决我的设置(我发现的任何解决方案都不管用)。所以请容忍我。。。 我的服务器主机名是IP地址,而不是域名(即URL看起来像:) 我的服务器有一个真正的证书(即,没有自签名) 我的应用程序的plist条目字典为空(没有任何例外-出厂设置ATS) 这是生产代码,我不能禁用ATS(我也不认为我可以,因为例外只适用于显式域名,而不是IP地址) (iOS9

  • 问题内容: 我正在尝试使用smack 4.1.0运行此代码 这给我一个错误: 并且,在本地openfire服务器中启用调试后,我收到以下消息: 我要去哪里错了? 问题答案: 根据与用户问题的讨论,AS位于XMPPTCPConnectionConfiguration中。默认情况下,Openfire中的端口5223是客户端SSL端口, 服务器>>服务器设置>>客户端连接 错误 org.jivesoft

  • 我在设置打开班次时遇到问题,并在连接到我的服务器域后收到以下错误: 我不确定这是在告诉我做什么。我尝试按字面意思使用指令,但它无法识别命令。 有什么想法吗?