Discovery-file Failed to find unicast hosts file – How to solve this Elasticsearch error

Opster Team

Aug-23, Version: 5-5

Briefly, this error occurs when Elasticsearch cannot locate the unicast hosts file, which is essential for node discovery in a cluster. This could be due to incorrect file path or insufficient permissions. To resolve this, ensure the file path in the ‘discovery.file’ setting is correct and the file exists. Also, check the file permissions to ensure Elasticsearch has access. If the file is missing, create it and add the IP addresses of the nodes in the cluster. Lastly, ensure the Elasticsearch process is restarted after making these changes.

This guide will help you check for common problems that cause the log ” [discovery-file] Failed to find unicast hosts file [{}] ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: discovery, discovery-file, hosts and plugins.

Log Context

Log “[discovery-file] Failed to find unicast hosts file [{}]” classname is FileBasedUnicastHostsProvider.java.
We extracted the following from Elasticsearch source code for those seeking an in-depth context :

         List hostsList;
        try (Stream lines = Files.lines(unicastHostsFilePath)) {
            hostsList = lines.filter(line -> line.startsWith("#") == false) // lines starting with `#` are comments
                             .collect(Collectors.toList());
        } catch (FileNotFoundException | NoSuchFileException e) {
            logger.warn((Supplier>) () -> new ParameterizedMessage("[discovery-file] Failed to find unicast hosts file [{}]";
                                                                        unicastHostsFilePath); e);
            hostsList = Collections.emptyList();
        } catch (IOException e) {
            logger.warn((Supplier>) () -> new ParameterizedMessage("[discovery-file] Error reading unicast hosts file [{}]";
                                                                        unicastHostsFilePath); e);




 

How helpful was this guide?

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?