# Determining the REST port for a node

**URL:** <https://discuss.elastic.co/t/determining-the-rest-port-for-a-node/10197>\
**Category:** Elasticsearch\
**Created:** [December 28, 2012, 10:44pm UTC](https://discuss.elastic.co/t/determining-the-rest-port-for-a-node/10197 "2012-12-28T22:44:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian\_Galkin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sebastian_galkin/32/2553_2.png) [@Sebastian\_Galkin](https://discuss.elastic.co/u/Sebastian_Galkin)\
**Post date:** [December 28, 2012, 10:44pm UTC](https://discuss.elastic.co/t/determining-the-rest-port-for-a-node/10197/1 "2012-12-28T22:44:35Z")

</div>

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

--

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [December 30, 2012, 11:04pm UTC](https://discuss.elastic.co/t/determining-the-rest-port-for-a-node/10197/2 "2012-12-30T23:04:50Z")

</div>

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](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](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

--

---

<div class="post-metadata">

**Author:** ![Sebastian\_Galkin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sebastian_galkin/32/2553_2.png) [@Sebastian\_Galkin](https://discuss.elastic.co/u/Sebastian_Galkin)\
**Post date:** [December 31, 2012, 6:58am UTC](https://discuss.elastic.co/t/determining-the-rest-port-for-a-node/10197/3 "2012-12-31T06:58:54Z")

</div>

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](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](https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/cluster/ClusterHealthTests.java)

That worked perfectly. Thanks a lot

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [December 31, 2012, 2:23pm UTC](https://discuss.elastic.co/t/determining-the-rest-port-for-a-node/10197/4 "2012-12-31T14:23:06Z")

</div>

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](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](https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/cluster/ClusterHealthTests.java)
> 
> That worked perfectly. Thanks a lot

--

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:58am UTC](https://discuss.elastic.co/t/determining-the-rest-port-for-a-node/10197/5 "2017-07-06T02:58:07Z")

</div>


