Elasticsearch indexing not working and error message: node null not part of the cluster Cluster [elasticsearch], ignoring
For those who met the same error and came here from search engines, make sure the TransportClient
is using the same cluster name as the cluster itself.
- Verify cluster name.
Visit http://localhost:9200 to check the cluster name. The default name is elasticsearch
. If you customised the cluster name using elasticsearch.yml
file, make sure the config file is picked up.
Set
culster.name
when creatingTransportClient
.Settings settings = ImmutableSettings.settingsBuilder() .put("cluster.name", clusterName) .put("client.transport.ignore_cluster_name", false) .put("node.client", true) .put("client.transport.sniff", true) .build();client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(host, port));
Ignore cluster name check
You can ignore the check of cluster name by setting client.transport.ignore_cluster_name
to true
.
- Debug if the error still exists
If the error still exists, launch your application in debug mode, and debug TransportClientNodesService
.
I had changed name on my dev elasticsearch server for the sake of experimenting and forgot about it.
The error message on the client were not that helpful, TransportClientNodeService makes a compare with the remote name but doesn't actually write the remote name ("cluster-name")in the log.
It is possible to bypass the name check with the following Spring configuration:
The resolution for me was to either:
- Change name of the cluster.name in elasticsearch server.
- Ignore cluster name of the client.
I went for both, this is my Spring config, hope it helps:
spring: ... data: elasticsearch: # Defaults to cluster-name 'elasticsearch' cluster-name: cluster-nodes: 127.0.0.1:9300 properties: # https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html client.transport.ignore_cluster_name: true