I think your clustername is myusername-elasticsearch-local
, right?
This is incorrect:
client = TransportClient.builder().build().
addTransportAddress(new InetSocketTransportAddress("localhost", 9200));
Should be 9300
and the code does not compile with 2.0. You should write something like:
Settings settings = Settings.settingsBuilder()
.put("cluster.name", clusterName).build();
Client client = TransportClient.builder().settings(settings).build()
.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("127.0.0.1", 9300)));
Actually this code is working for me.