Hello,
I'm having trouble connecting to elasticsearch through the Java API. I
have two servers, each running elastic search and my java application
(Play! Framework). I can connect to elasticsearch using curl on port
9200, for example:
$ curl -XGET server1:9200/_cluster/health
{"cluster_name":"elasticsearch","status":"yellow","timed_out":false,"number_of_nodes":
1,"number_of_data_nodes":1,"active_primary_shards":5,"active_shards":
5,"relocating_shards":0,"initializing_shards":0,"unassigned_shards":5}
But when I try to connect with the Java API on port 9300, I get a
NoNodeAvailableException. I've opened ports 9200 and 9300 on my
firewall. The ES log on each server, and the cluster health above,
seem to indicate that the two instances of elastic search aren't
connecting to each other. I read in a few other threads that this is
often caused by mismatched cluster names, but I'm using the default
value, "elasticsearch".
What am I doing wrong?
Stack trace:
play.exceptions.JavaExecutionException: No node available
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:229)
at Invocation.HTTP Request(Play!)
Caused by:
org.elasticsearch.client.transport.NoNodeAvailableException: No node
available
at
org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:
145)
at
org.elasticsearch.client.transport.support.InternalTransportClusterAdminClient.state(InternalTransportClusterAdminClient.java:
125)
at controllers.Search.index(Search.java:36)
/etc/elasticsearch/elasticsearch.yml config file (Elastic search is
set up as a service, as described at
http://www.elasticsearch.org/tutorials/2010/07/02/setting-up-elasticsearch-on-debian.html):
cluster:
name: elasticsearch
network:
host: eth1:ipv4
Elastic Search logs:
Server 1:
[2011-12-22 16:47:25,350][INFO ][node ] [Fight-
Man] {0.18.6}[1605]: initializing ...
[2011-12-22 16:47:25,365][INFO ][plugins ] [Fight-
Man] loaded [], sites []
[2011-12-22 16:47:28,228][INFO ][node ] [Fight-
Man] {0.18.6}[1605]: initialized
[2011-12-22 16:47:28,229][INFO ][node ] [Fight-
Man] {0.18.6}[1605]: starting ...
[2011-12-22 16:47:28,324][INFO ][transport ] [Fight-
Man] bound_address {inet[/10.182.35.60:9300]}, publish_address {inet[/
10.182.1.2:9300]}
[2011-12-22 16:47:31,369][INFO ][cluster.service ] [Fight-
Man] new_master [Fight-Man][D_A18QcATlaFPE28FI5-gg][inet[/
10.182.1.2:9300]], reason: zen-disco-join (elected_as_master)
[2011-12-22 16:47:31,444][INFO ][discovery ] [Fight-
Man] elasticsearch/D_A18QcATlaFPE28FI5-gg
[2011-12-22 16:47:31,678][INFO ][http ] [Fight-
Man] bound_address {inet[/10.182.35.60:9200]}, publish_address {inet[/
10.182.1.2:9200]}
[2011-12-22 16:47:31,679][INFO ][node ] [Fight-
Man] {0.18.6}[1605]: started
[2011-12-22 16:47:32,393][INFO ][gateway ] [Fight-
Man] recovered [1] indices into cluster_state
Server 2:
[2011-12-22 16:52:10,402][INFO ][node ] [Jack-in-
the-Box] {0.18.6}[1799]: initializing ...
[2011-12-22 16:52:10,411][INFO ][plugins ] [Jack-in-
the-Box] loaded [], sites []
[2011-12-22 16:52:13,505][INFO ][node ] [Jack-in-
the-Box] {0.18.6}[1799]: initialized
[2011-12-22 16:52:13,507][INFO ][node ] [Jack-in-
the-Box] {0.18.6}[1799]: starting ...
[2011-12-22 16:52:13,659][INFO ][transport ] [Jack-in-
the-Box] bound_address {inet[/10.182.33.113:9300]}, publish_address
{inet[/10.182.3.4:9300]}
[2011-12-22 16:52:16,815][INFO ][cluster.service ] [Jack-in-
the-Box] new_master [Jack-in-the-Box][tCfshMH-Q1KbsK6eYUTthw][inet[/
10.182.3.4:9300]], reason: zen-disco-join (elected_as_master)
[2011-12-22 16:52:16,857][INFO ][discovery ] [Jack-in-
the-Box] elasticsearch/tCfshMH-Q1KbsK6eYUTthw
[2011-12-22 16:52:16,950][INFO ][http ] [Jack-in-
the-Box] bound_address {inet[/10.182.33.113:9200]}, publish_address
{inet[/10.182.3.4:9200]}
[2011-12-22 16:52:16,953][INFO ][node ] [Jack-in-
the-Box] {0.18.6}[1799]: started
[2011-12-22 16:52:16,967][INFO ][gateway ] [Jack-in-
the-Box] recovered [0] indices into cluster_state
My Java code:
public class Search extends Controller {
@Get("/cluster")
public static void index() {
Settings settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", "elasticsearch").build();
TransportClient client = new TransportClient(settings)
.addTransportAddress(new
InetSocketTransportAddress("10.182.1.2", 9300))
.addTransportAddress(new
InetSocketTransportAddress("10.182.3.4", 9300));
ActionFuture response =
client.admin().cluster().state(new ClusterStateRequest()); // Throws
exception
renderText(response.actionGet().getClusterName().toString());
}
@Get("/cluster/node")
public static void node() {
Node node = nodeBuilder().data(false).node();
Client client = node.client();
ActionFuture<ClusterStateResponse> response =
client.admin().cluster().state(new ClusterStateRequest());
renderText(response.actionGet().state().getNodes().dataNodes().keySet()); //
Output is []
}
}
iptables rules:
ACCEPT tcp -- server1 anywhere tcp dpt:9200
ACCEPT tcp -- server2 anywhere tcp dpt:9200
ACCEPT udp -- server1 anywhere udp dpt:9300
ACCEPT udp -- server2 anywhere udp dpt:9300
ACCEPT tcp -- server1 anywhere tcp dpt:9300
ACCEPT tcp -- server2 anywhere tcp dpt:9300