2

I am trying to use elasticsearch in java through TransportClient. I have used logstash to integrate mysql with elasticsearch. This is how i have initialized and used transport client

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

I am unable to connect to the node and i get a handshake timeout. I get the following error:

TransportClientNodesService - failed to connect to node 
[{#transport#-1}{vrvVU4MGTAC7_5NCOiBseg}{localhost}{127.0.0.1:9200}], 
ignoring...
org.elasticsearch.transport.ConnectTransportException: [][127.0.0.1:9200] handshake_timeout[30s]
at org.elasticsearch.transport.TcpTransport.executeHandshake(TcpTransport.java:1614) ~[elasticsearch-5.5.2.jar:5.5.2]
at org.elasticsearch.transport.TcpTransport.openConnection(TcpTransport.java:555) ~[elasticsearch-5.5.2.jar:5.5.2]
at org.elasticsearch.transport.TcpTransport.openConnection(TcpTransport.java:116) ~[elasticsearch-5.5.2.jar:5.5.2]
at org.elasticsearch.transport.TransportService.openConnection(TransportService.java:351) ~[elasticsearch-5.5.2.jar:5.5.2]
at org.elasticsearch.client.transport.TransportClientNodesService$SimpleNodeSampler.doSample(TransportClientNodesService.java:407) [elasticsearch-5.5.2.jar:5.5.2]
at org.elasticsearch.client.transport.TransportClientNodesService$NodeSampler.sample(TransportClientNodesService.java:357) [elasticsearch-5.5.2.jar:5.5.2]
at org.elasticsearch.client.transport.TransportClientNodesService$ScheduledNodeSampler.run(TransportClientNodesService.java:390) [elasticsearch-5.5.2.jar:5.5.2]
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:569) [elasticsearch-5.5.2.jar:5.5.2]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_131]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]
Vaibhav Savala
  • 315
  • 2
  • 7
  • 17

1 Answers1

4

Elasticsearch transport port is 9300 so change your client creation line by replacing 9200 with 9300 as shown below:

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

Find the related documentation here.

If you are using different cluster.name other than default(elasticsearch) then you must set that while creating TransportClient as shown below:

Settings settings = Settings.builder()
        .put("cluster.name", "myClusterName").build();
TransportClient client = new PreBuiltTransportClient(settings);
//Add transport addresses and do something with the client...
avr
  • 4,835
  • 1
  • 19
  • 30
  • should I change the port to 9300 in my logstash.conf file and elsewhere as well or only here? – Vaibhav Savala Sep 12 '17 at 11:07
  • Only in above line. – avr Sep 12 '17 at 11:09
  • Getting the error as 'not part of the cluster Cluster [elasticsearch], ignoring...' – Vaibhav Savala Sep 12 '17 at 11:14
  • Have you configured different `cluster.name` then you must provide the cluster name to your transport client. You can find the code to set the cluster name (here)[https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html#transport-client] – avr Sep 12 '17 at 11:27
  • Yes, i have solved that issue. Thanks a lot. I found the solution to this here. https://stackoverflow.com/questions/27170739/elasticsearch-indexing-not-working-and-error-message-node-null-not-part-of-the – Vaibhav Savala Sep 12 '17 at 11:31