Error client.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300));

hi All developers
i have i error in my projetct
Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{zSavWRA4QBGzdYdox-h2Aw}{localhost}{127.0.0.1:9300}]]
att

My code :

@Bean
public Client client(){
TransportClient client = null;
try{
System.out.println("host:"+ host+"port:"+port);
final Settings elasticsearchSettings = Settings.builder()
.put("client.transport.sniff", true)
.put("cluster.name", clusterName).build();
/client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new TransportAddress(InetAddress.getByName(host), port));
/
client = new PreBuiltTransportClient(Settings.EMPTY);
client.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300));
} catch (UnknownHostException e) {
e.printStackTrace();
}
return client;
}
@Bean
public ElasticsearchOperations elasticsearchTemplate() {
return new ElasticsearchTemplate(client());
}

public String getHost() {
    return host;
}
public int getPort() {
    return port;
}

public void setHost(String host) {
    this.host = host;
}

public void setPort(int port) {
    this.port = port;
}

public String getClusterName() {
    return clusterName;
}

public void setClusterName(String clusterName) {
this.clusterName = clusterName;

}

Don't use the TransportClient. It has been deprecated and will be removed. Use the rest client instead.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.