I am trying to use ElasticSearch 5.4.0 to create a TransportClient
and utilize it for indexing records in my local ES cluster. The client, I have created, is as follows:
@SuppressWarnings({ "resource", "unchecked" })
protected static Client getTransportClient() {
try {
Settings settings = Settings.builder()
.put("xpack.security.user", "username:password")
//.put("xpack.security.enabled", false)
.build();
InetSocketTransportAddress inetAddress = new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300);
client = new PreBuiltXPackTransportClient(settings).addTransportAddress(inetAddress);
} catch (UnknownHostException e) {
LOGGER.log(Level.WARNING, e.getMessage());
}
return client;
}
But, when I try to use the client to prepare an index as follows:
IndexResponse response = client.prepareIndex(INDEX, TYPE)
.setSource(json).execute().actionGet();
i got the following error:
Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{Vydx3TkcTReJh71fcCjqQg}{127.0.0.1}{127.0.0.1:9300}]]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:348)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:246)
at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59)
at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:366)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:408)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54)
at org.personal.elastic.twitter.ElasticUtil.indexTweet(ElasticUtil.java:44)
at org.personal.elastic.twitter.TweetHunter.main(TweetHunter.java:39)
The error log itself didn't help much, so I looked up further. I found out that my ES node was, in fact, found out but was dropped during network handshake. The internal error log (which didn't show up in the previous stack trace) can be found here: https://pastebin.com/j5n52pN6
Could someone help me resolving this issue, which looks like related to ES x-pack authentication. Please let me know, if any further information is required.