# Transport Client: get address(es) from settings?

**URL:** https://discuss.elastic.co/t/transport-client-get-address-es-from-settings/5809
**Category:** Elasticsearch
**Created:** [November 8, 2011, 11:11am UTC](https://discuss.elastic.co/t/transport-client-get-address-es-from-settings/5809 "2011-11-08T11:11:11Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Andrew\_Regan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_regan/32/3080_2.png) [@Andrew\_Regan](https://discuss.elastic.co/u/Andrew_Regan)
#### Post date: [November 8, 2011, 11:11am UTC](https://discuss.elastic.co/t/transport-client-get-address-es-from-settings/5809/1 "2011-11-08T11:11:11Z")

</div>

Sounds like a newbie-ish kind of question, but I can't find an answer  
anywhere. All over the place I'm seeing the following approach used for  
pointing a Client at an ES cluster:

new TransportClient(...).addTransportAddress( new  
InetSocketTransportAddress( "host", port))

But I'd like to configure the TransportClient entirely from a separate  
YAML/JSON. What syntax can I use to express the transport address there, so  
that 'new TransportClient(settings)' does the whole thing, without the  
hardcoding?

---

<div class="post-metadata">

### Author: ![Frederic](https://avatars.discourse-cdn.com/v4/letter/f/4491bb/32.png) [@Frederic](https://discuss.elastic.co/u/Frederic)
#### Post date: [November 8, 2011, 1:47pm UTC](https://discuss.elastic.co/t/transport-client-get-address-es-from-settings/5809/2 "2011-11-08T13:47:50Z")

</div>

Hi Andrew,

Don't take this as the best approach at all but, it worked for me at  
least. If someone sees any issue here, please point it out.

Briefly you could use a for loop to iterate for each one of the hosts  
defined in your YAML/JSON and call addTransportAddress

Full code here [ElasticSearch Client Factory · GitHub](https://gist.github.com/1347758)

protected static Client createTransportClient(clusterName, port,  
hosts, sniffCluster) {  
logger.info("Creating Elasticsearch Transport Client for  
cluster [$clusterName] and hosts $hosts at port $port")

```
    Settings settings =

```

ImmutableSettings.settingsBuilder().put("cluster.name", clusterName)  
.put("node.client",  
true)  
.put("client.transport.sniff",  
sniffCluster)  
.build()  
Client client = new TransportClient(settings)

```
    hosts.each { host ->
        client.addTransportAddress(new

```

InetSocketTransportAddress(host, port))  
}

```
    return client
}

```

On 8 nov, 08:11, Andrew Regan [are...@gmail.com](mailto:are...@gmail.com) wrote:

> Sounds like a newbie-ish kind of question, but I can't find an answer  
> anywhere. All over the place I'm seeing the following approach used for  
> pointing a Client at an ES cluster:
> 
> new TransportClient(...).addTransportAddress( new  
> InetSocketTransportAddress( "host", port))
> 
> But I'd like to configure the TransportClient entirely from a separate  
> YAML/JSON. What syntax can I use to express the transport address there, so  
> that 'new TransportClient(settings)' does the whole thing, without the  
> hardcoding?

---

<div class="post-metadata">

### Author: ![Andrew\_Regan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_regan/32/3080_2.png) [@Andrew\_Regan](https://discuss.elastic.co/u/Andrew_Regan)
#### Post date: [November 8, 2011, 11:51pm UTC](https://discuss.elastic.co/t/transport-client-get-address-es-from-settings/5809/3 "2011-11-08T23:51:04Z")

</div>

Hi Frederic,

I've gone with your suggestion - looks like the best option at the moment!

Thanks,

Andrew

---

<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, 3:49am UTC](https://discuss.elastic.co/t/transport-client-get-address-es-from-settings/5809/4 "2017-07-06T03:49:29Z")

</div>


