I use this old version of elasticsearch version:
implementation 'org.elasticsearch:elasticsearch:5.6.15'
implementation 'org.elasticsearch.client:transport:5.6.15'
implementation 'org.elasticsearch.plugin:transport-netty4-client:5.6.15'
I tried to use this code to connect to a single node cluster version 7.17.18
:
Settings settings = Settings.builder().put("cluster.name", "my-application").build();
TransportClient client = new PreBuiltTransportClient(settings);
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("elhost"), 9200));
I get always error during connection:
00:36:55.575 [Test worker] DEBUG org.elasticsearch.client.transport.TransportClientNodesService - failed to connect to node [{#transport#-1}{HMVGc-VRQKaQd94qprZcNQ}{elhost}{192.168.1.112:9200}], ignoring...
org.elasticsearch.transport.ConnectTransportException: [][192.168.1.112:9200] handshake_timeout[30s]
I suspect that the reason for this is version incompatibility. Do you know which version of elasticsearch server is compatible with this client version?
There are two issues here.
First of all, version will be definitely an issue here, especially with transport client, which is using binary serialization and very sensitive to the version of elasticsearch it talks to. Ideally you would want to use the transport client with the same version of elasticsearch cluster (5.6.15 in your case). There is some compatibility layer that allows a 5.x client to talk to other 5.x nodes, so theoretically other 5.x versions should work as well. But for the best result I would use 5.6.15 since it was the latest in 5.x series. Saying this, v5.6.15 is almost 5 years old, it hasn't been supported and haven't receive any security updates for years now. So, I cannot recommend using it, especially if you are starting a new project. It would be much more prudent to use a modern version of elasticsearch with a modern version of elasticsearch client.
The second issue is you are connecting to a wrong port. Port 9200 is used for REST API (and REST Clients). Transport clients need to connect on another port - 9300.