# API to get bounded port

**URL:** <https://discuss.elastic.co/t/api-to-get-bounded-port/20443>\
**Category:** Elasticsearch\
**Created:** [October 27, 2014, 6:36am UTC](https://discuss.elastic.co/t/api-to-get-bounded-port/20443 "2014-10-27T06:36:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [October 27, 2014, 6:36am UTC](https://discuss.elastic.co/t/api-to-get-bounded-port/20443/1 "2014-10-27T06:36:40Z")

</div>

When starting a cluster via testing, I want to get the bounded port since I  
am letting choose and there might be a conflict.

Here is the ugly and brittle code I came up to do this:

> <https://gist.github.com/ppearcy/c5d969326b9e6ace8046>

Is there a nicer API than having to regex out the connection string?

Thanks,  
Paul

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2a10a6e4-5f01-45f4-a9b8-0be5d35546a0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2a10a6e4-5f01-45f4-a9b8-0be5d35546a0%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [October 27, 2014, 10:07am UTC](https://discuss.elastic.co/t/api-to-get-bounded-port/20443/2 "2014-10-27T10:07:45Z")

</div>

Not sure why you convert the "publish" address to a string, in Java you can  
find the current transport port with

```
    // find node address
    NodesInfoRequest nodesInfoRequest = new

```

NodesInfoRequest().transport(true);  
NodesInfoResponse response =  
client.admin().cluster().nodesInfo(nodesInfoRequest).actionGet();  
Object obj =  
response.iterator().next().getTransport().getAddress().publishAddress();  
if (obj instanceof InetSocketTransportAddress) {  
InetSocketTransportAddress address =  
(InetSocketTransportAddress) obj;  
// ... process host and port from address  
}  
if (obj instanceof LocalTransportAddress) {  
LocalTransportAddress address = (LocalTransportAddress) obj;  
// .... process local address, no host/port  
}

which is, I admit, still not pretty.

Note, if you have a node set to "local(true)", there is no host/port, but a  
LocalTransportAddress.

Jörg

On Mon, Oct 27, 2014 at 7:36 AM, ppearcy [ppearcy@gmail.com](mailto:ppearcy@gmail.com) wrote:

> When starting a cluster via testing, I want to get the bounded port since  
> I am letting choose and there might be a conflict.
> 
> Here is the ugly and brittle code I came up to do this:  
> [Elasticsearch get bounded port · GitHub](https://gist.github.com/ppearcy/c5d969326b9e6ace8046)
> 
> Is there a nicer API than having to regex out the connection string?
> 
> Thanks,  
> Paul
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/2a10a6e4-5f01-45f4-a9b8-0be5d35546a0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2a10a6e4-5f01-45f4-a9b8-0be5d35546a0%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/2a10a6e4-5f01-45f4-a9b8-0be5d35546a0%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/2a10a6e4-5f01-45f4-a9b8-0be5d35546a0%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoHDHKvokqgZ50AAVK%3D4Mvie73ifs%3DhbkcO%3Dw%2BCEWMtFKQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoHDHKvokqgZ50AAVK%3D4Mvie73ifs%3DhbkcO%3Dw%2BCEWMtFKQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:53am UTC](https://discuss.elastic.co/t/api-to-get-bounded-port/20443/3 "2017-07-06T00:53:45Z")

</div>


