I'm trying to make my first Java application to talk to ElasticSearch, which is running on this node (timestamps removed):
$ bin/elasticsearch
[2015...][WARN ][bootstrap ] Unable to lock JVM Memory: error=78,reason=Function not implemented
[2015...][WARN ][bootstrap ] This can result in part of the JVM being swapped out.
[2015...][INFO ][node ] [clustername.01] version[2.0.0], pid[49252], build[de54438/2015-10-22T08:09:48Z]
[2015...][INFO ][node ] [clustername.01] initializing ...
[2015...][INFO ][plugins ] [clustername.01] loaded [license, marvel], sites []
[2015...][INFO ][env ] [clustername.01] using [1] data paths, mounts [[/ (/dev/disk1)]], net usable_space [164.4gb], net total_space [232.5gb], spins? [unknown], types [hfs]
[2015...][INFO ][node ] [clustername.01] initialized
[2015...][INFO ][node ] [clustername.01] starting ...
[2015...][INFO ][transport ] [clustername.01] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300}
[2015...][INFO ][discovery ] [clustername.01] myusername-elasticsearch-local/AM4lm0ZBS_6FofhC0UbNIA
[2015...][INFO ][cluster.service ] [clustername.01] new_master {clustername.01}{AM4lm0ZBS_6FofhC0UbNIA}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-join(elected_as_master, [0] joins received)
[2015...][INFO ][http ] [clustername.01] publish_address {127.0.0.1:9200}, bound_addresses {127.0.0.1:9200}
[2015...][INFO ][node ] [clustername.01] started
[2015...][INFO ][license.plugin.core ] [clustername.01] license [3ff50767-f1a5-4bac-8e35-c7a131384fd9] - valid
[2015...][ERROR][license.plugin.core ] [clustername.01]
[2015...][INFO ][gateway ] [clustername.01] recovered [14] indices into cluster_state
I've confirmed the IP and port is running:
$ bin/elasticsearch --version Version: 2.0.0, Build: de54438/2015-10-22T08:09:48Z, JVM: 1.8.0_45 $ telnet 127.0.0.1 9300 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. ^CConnection closed by foreign host. $ telnet 127.0.0.1 9301 Trying 127.0.0.1... telnet: connect to address 127.0.0.1: Connection refused telnet: Unable to connect to remote host $
9300 is there, 9301 isn't. I'm reasonably sure that port 9300 is correct for a Java TransportClient.
But this
public class TrivialClient {
public static void main(String[] args) throws UnknownHostException {
Client client = TransportClient.builder().build().
addTransportAddress(new InetSocketTransportAddress(
InetAddress.getLocalHost(), 9300));
printResponse("getLocalHost", client);
client = TransportClient.builder().build().
addTransportAddress(new InetSocketTransportAddress(
InetAddress.getByName("localhost"), 9300));
printResponse("getByName(\"localhost\")", client);
client = TransportClient.builder().build().
addTransportAddress(new InetSocketTransportAddress(
InetAddress.getByAddress(new byte[] {127, 0, 0, 1}), 9300));
printResponse("getByAddress(new byte[] {127, 0, 0, 1})", client);
}
private static void printResponse(String description, Client client) {
try {
GetResponse response = client.prepareGet("comicbook", "superhero", "1").get();
System.out.println(description + ": " + response);
} catch (NoNodeAvailableException e) {
System.out.println(description + ": " + e);
}
}
}
Outputs this
getLocalHost: NoNodeAvailableException[None of the configured nodes are available: []]
getByName("localhost"): NoNodeAvailableException[None of the configured nodes are available: []]
getByAddress(new byte[] {127, 0, 0, 1}): NoNodeAvailableException[None of the configured nodes are available: []]
This
client = TransportClient.builder().build().
addTransportAddress(new InetSocketTransportAddress("localhost", 9200));
which is valid according to this question, does not even compile.
My clustername is different, so I've also tried it with this at the top
Settings settings = Settings.settingsBuilder()
.put("cluster.name", "clustername").build();
(and added settings(settings) to each builder), but same error.
What am I missing?
