I am trying to connect to an ElasticSearch server using the Java API. I using elasticsearch service to start/stop and elasticsearch head for visualising the cluster. The clu
First, version is really important, Java API is strong related with the version you are using,
This solution works in elasticSearch v 5.4.1 with java 8
make sure that you are getting all dependencies, and the child dependencies (not only elasticSearch jar), use maven, ivy etc for getting the dependencies tree.
in ivy for example :
//--------------------- then in a class you can call:
TransportClient client;
client = new PreBuiltTransportClient(Settings.EMPTY).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));