I have added an env variable in elasticsearch.yml file as follows
http.port: ${PORT}
I am able to retrieve the value of this variable when I echo the value of the variable
echo $PORT
9200
But the Elasticsearch do not start with this configuration. Infact it do not start at when I use ${} values and only does when i comment it out or substitute it with actual values.
Please help me with any configuration that I am missing.
I'm doing exactly the same and it works for me, but you must remember to export PORT in the environment of the user that starts Elasticsearch which may be a different user from the one you're logged in as.
One way around this problem is to use a wrapper script to set the environment variable and start Elasticsearch. For instance a start-es.sh with this content:
Then you just run ./start.es.sh when you want to start Elasticsearch with the right PORT setting.
Of course, you can then expand the script to add even more environment variables, for instance node and cluster name, zen discovery hosts, data path etc making elasticsearch.yml completely generic across all nodes and even across clusters, making maintenance a breeze.
Found the solution for this
As mentioned the below link
As I am running elasticsearch as a linux service, rather than a shell application, it has access to no environment variables except for a very select few.
I added the following line to the end of /etc/sysconfig/elasticsearch to load the environment variables I wanted available to the program:
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.