Can you set ES node name to same as the machine hostname?

Is it possible to use environment variables or similar to automatically set an Elasticsearch node name to the hostname of the machine?

i.e. if a machine is called ES1, the ES node name would also be ES1 without having to configure it in elasticsearch.yml manually?

1 Like

Yes, you can substitute any environment variable in elasticsearch.yml by using ${...} notation, such as:

node.name: ${HOSTNAME}
1 Like

Perfect - thank you. I tried to find something about this in the documentation but clearly wasn't looking in the right place!

I found that I had to add the following line to /etc/init.d/elasticsearch script (on Ubuntu):

export NODENAME=`hostname`

N.B. Important that you use back ticks for this

and then update elasticsearch.yml to:

node.name: ${NODENAME}

I wouldn't edit the init script, this can change between versions and you might find an upgrade will break it.

Thanks for the advice @warkolm - I'll look into alternative ways of setting the env variable!