Elasticsearch: No alive nodes found in your cluster
Typical causes and solutions for the No alive nodes found in your cluster error with Elasticsearch.

By. Jacob
Edited: 2023-10-16 09:02
The No alive nodes found in your cluster error typically indicates that Elasticsearch is unavailable. While this can happen for a number of reasons, the specific reason may be hinted in the status or Elasticsearch log files.
The status can be checked with systemctl:
systemctl status elasticsearch
Running this command might give the following output:
Jul 27 08:42:24 lima-shopware systemd[1]: Starting Elasticsearch...
Jul 27 08:42:31 lima-shopware systemd[1]: Started Elasticsearch.
Jul 27 10:32:39 lima-shopware systemd[1]: elasticsearch.service: A process of this unit has been killed by the OOM killer.
Jul 27 10:32:39 lima-shopware systemd-entrypoint[2610]: ERROR: Elasticsearch exited unexpectedly
Jul 27 10:32:39 lima-shopware systemd[1]: elasticsearch.service: Failed with result 'oom-kill'.
Jul 27 10:32:39 lima-shopware systemd[1]: elasticsearch.service: Consumed 1min 1.125s CPU time.
As you can deduce from this, in my case the cause for No alive nodes found in your cluster is that Elasticsearch was killed due to running out of memory. The solution is to either increase the available memory in the system itself or decrease the java heap size.
If you are just running in a test environment, such as in a VM, docker container, or even a small cloud instance, you may be able to run Elasticsearch with less ram than you would in a live environment. In this case, you can try to decrease the java heap size as much as possible. E.g. Edit /etc/elasticsearch/jvm.options.d/custom.options and start with 1 GB:
-Xms1g
-Xmx1g
But if possible, also try experimenting with making more memory available in your instance. It is typically recommended to run Elasticsearch in a separate instance, so it does not compete with other services for memory – but in my opinion this really should not be necessary, especially not in development-setups.
When trying to access your website you may get 500 Internal Server error if running in prod mode, or more specifically, if you are testing your site in dev mode, the actual cause for the error might show as: No alive nodes found in your cluster.
If you read the message closely, then you can tell that Elasticsearch was unexpectedly terminated by the Linux OOM killer, which indicates that the system itself may be running low on memory.
In my own case, I got this error on a Shopware website that I am working on in a local dev environment. If you are also on Shopware, you can change to dev mode in your .env file of your website root, as this may show the actual error in your browser rather than just the typical 500 internal server error message.
Specific to Shopware 6.5+
In Shopware 6.5+ you can configure Elasticsearch or Opensearch for both the Storefront and the administration backend; if you neglect the backend, you may get the No alive nodes found in your cluster message when attempting to hit save or perform other actions within the backend, and this is "seemingly" despite the fact you may think it is already configured correctly, because "it works in the storefront". To fix it, you need to configure search for both the Storefront and the Administration. E.g. Within your .env.local file:
OPENSEARCH_URL="http://opensearch-node1:9200"
SHOPWARE_ES_HOSTS="http://opensearch-node1:9200"
SHOPWARE_ES_INDEXING_ENABLED="1"
SHOPWARE_ES_ENABLED="1"
SHOPWARE_ES_INDEX_PREFIX="sw"
SHOPWARE_ES_THROW_EXCEPTION=1
ADMIN_OPENSEARCH_URL="http://opensearch-node1:9200"
SHOPWARE_ADMIN_ES_ENABLED=1
SHOPWARE_ADMIN_ES_REFRESH_INDICES=1
SHOPWARE_ADMIN_ES_INDEX_PREFIX=sw-admin
You will also need to make sure that other configuration files are using the OPENSEARCH_URL environment variable. E.g: config/packages/elasticsearch.yaml.
Note. Opensearch is a fork of Elasticsearch that can more or less be used and configured the same way.
Tell us what you think: