If you’re getting the following error message when you try to access your Elasticsearch service:

$ curl http://localhost:9200/
Failed to connect to localhost port 9200: Connection refused

This is likely because your Elasticsearch is not listening on the correct IP address of your network. For example, this is a common issue when you run Elasticsearch inside Docker.

To fix this, open /etc/elasticsearch/elasticsearch.yml and add this:

network.host: 0.0.0.0

This instructs Elasticsearch service to listen on all local addresses and will get you going.

However, to be safe, you should set network.host to a specific correct IP address of your network that is assigned to your host.