Failed to connect to XX.XX.XXX.XX port 9200: Connection refused on EC2 Failed to connect to XX.XX.XXX.XX port 9200: Connection refused on EC2 elasticsearch elasticsearch

Failed to connect to XX.XX.XXX.XX port 9200: Connection refused on EC2


I have solved the problem.

First thing I had to configure was network.host, but very important to notice that it didn't work with the IP I was trying to connect to from the client, because this is the EC2 public IP. I had to use the EC2 private IP.

But then I kept getting the same error, and I've found out that the cluster coordination algorithm has changed in Elasticsearch 7.0 and in order to be safe it requires some specific configuration. Elastic relax that requirement (that is, they run in a less-safe mode) when one binds to localhost only, but if/when one changes network.host they enforce that he configures the cluster safely.

So, since I use a single node cluster, I had to add the following setting to the Discovery section in elasticsearch.yml:

discovery.type: single-node


please add the following line in elasticsearch.yml and restart elasticsearch service:

network.host: xxx.xxx.xxx.xxx 

xxx.xxx.xxx.xxx is your elasticsearch server's IP address