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

client.close();

What is host1 and host2 ?
I get an error while running the java program. The error is:
Exception in thread "main" java.net.UnknownHostException: host1: nodename nor servname provided, or not known
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
at java.net.InetAddress.getAllByName(InetAddress.java:1192)
at java.net.InetAddress.getAllByName(InetAddress.java:1126)
at java.net.InetAddress.getByName(InetAddress.java:1076)
at Sherlock.ESTest1.javaApi.main(javaApi.java:21)

How do I resolve this?

I'm using a single node cluster.
By changing host1 to 127.0.0.1, 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:
https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html

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.