Hi all.
First for all, i'm sorry for my english.
I have a problem with Java API Transport Client. I have one master node and three data nodes.
I try to connect to my cluster with Transport Client and then i response "NoNodeAvailableException[None of the configured nodes are available".
That is my code of client:
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.xpack.client.PreBuiltXPackTransportClient;
public class Main {
private static String[] hosts = new String[] {
"XX.XX.X.XXX"
,"XX.XX.X.XXX"
,"XX.XX.X.XXX"
,"XX.XX.X.XXX"
};
private static final Settings settings = Settings.builder()
.put("cluster.name", "myCluster")
.put("client.transport.sniff", true)
.put("transport.tcp.port", 9300)
.put("xpack.security.user", "transport_client_user:changeme")
.build();
private static final String index = "myIndex";
private static final String type = "myType";
private static TransportClient client;
public static void main(String[] args) throws UnknownHostException {
InetSocketTransportAddress[] ista = new InetSocketTransportAddress[hosts.length];
for (int i = 0; i < hosts.length; i++) {
ista[i] = new InetSocketTransportAddress(InetAddress.getByName(hosts[i]), 9300);
}
client = new PreBuiltXPackTransportClient(settings).addTransportAddresses(ista);
SearchRequestBuilder rb = client
.prepareSearch(index)
.setTypes(type)
.setSearchType(SearchType.DEFAULT)
.setQuery(QueryBuilders.termQuery("_id", 3524598));
SearchResponse sResponse = rb.get();
System.out.println(sResponse.toString());
}
}
Port for transport client - 9300, all my nodes communicate under this port. I saw a lot like my question, and i trying to follow the advice contained in them. But i have the same exception.
If need more information or any files or settings of my Elastic - i'm ready to answer.