Determining the REST port for a node

I'm using NodeBuilder to create a Local node to be used for functional
tests. I'm using the default configuration, but setting "node.local" to
true and reducing the number of shards and replicas.

If ES is already running in my localhost when I launch the new node, it
will use a different port, the first one available. How can I determine,
given a Node instance, in which port it's actually listening for REST
requests?

Thanks

--

I assume you mean retrieving info about the REST HTTP address from Java.

If your node is a cluster member, execute the cluster admin command for the
cluster nodes info

https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/action/admin/cluster/node/info

similar to this example where the cluster health is requested

https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/cluster/ClusterHealthTests.java

Watch out for the 'http_address' field in the response.

If your node is not a cluster member, and if you know the cluster name, you
should first join the cluster.

If your node is not a cluster member, and you do not know the cluster name,
you can't find out the 'http_address' (you can only guess it's on the
default range 9200-9299 but this may be false)

Jörg

On Friday, December 28, 2012 11:44:35 PM UTC+1, Sebastián Galkin wrote:

I'm using NodeBuilder to create a Local node to be used for functional
tests. I'm using the default configuration, but setting "node.local" to
true and reducing the number of shards and replicas.

If ES is already running in my localhost when I launch the new node, it
will use a different port, the first one available. How can I determine,
given a Node instance, in which port it's actually listening for REST
requests?

Thanks

--

Jörg Prante wrote:

If your node is a cluster member, execute the cluster admin command for
the cluster nodes info

https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/action/admin/cluster/node/info

similar to this example where the cluster health is requested

https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/cluster/ClusterHealthTests.java

That worked perfectly. Thanks a lot

--

Here is another somewhat hacky but more direct way to do it:

((InternalNode)
node).injector().getInstance(HttpServerTransport.class).boundAddress().publishAddress()

On Monday, December 31, 2012 1:58:54 AM UTC-5, Sebastián Galkin wrote:

Jörg Prante wrote:

If your node is a cluster member, execute the cluster admin command for
the cluster nodes info

https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/action/admin/cluster/node/info

similar to this example where the cluster health is requested

https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/cluster/ClusterHealthTests.java

That worked perfectly. Thanks a lot

--