Declaring java client in elastic search?

How do I declare a java client?
From the current documentation, it is done using
// on startup

TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300));

// on shutdown


What is host1 and host2 ?
I get an error while running the java program. The error is:
Exception in thread "main" host1: nodename nor servname provided, or not known
at Method)
at Sherlock.ESTest1.javaApi.main(

How do I resolve this?

I'm using a single node cluster.
By changing host1 to, the program worked.
I believe, host1 and host2 are the names of the nodes.

PS: If anyone has the documentation on how to included more nodes, please let me know.

You can define explicit hosts in your TransportClient by calling
the addTransportAddress method as highlighted in the documentation:

However, if you are getting an UnknownHostException, that means your name
server is not resolving the name. Depending on your OS, you can use system
tools to verify the host name:

% nslookup host

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