Failed to read file unicastHostsFilePath – How to solve this Elasticsearch error

Opster Team

Aug-23, Version: 8.3-8.9

Briefly, this error occurs when Elasticsearch cannot read the file specified in the unicastHostsFilePath. This could be due to incorrect file path, insufficient permissions, or the file not existing. To resolve this issue, you can verify the file path and ensure it’s correct. Check the file permissions to ensure Elasticsearch has the necessary read access. If the file doesn’t exist, create it. Also, ensure the file is in the correct format as expected by Elasticsearch.

This guide will help you check for common problems that cause the log ” failed to read file [” + unicastHostsFilePath + “] ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: hosts, discovery.

Log Context

Log “failed to read file [” + unicastHostsFilePath + “]” classname is FileBasedSeedHostsProvider.java.
We extracted the following from Elasticsearch source code for those seeking an in-depth context :

        if (Files.exists(unicastHostsFilePath)) {
            try (Stream lines = Files.lines(unicastHostsFilePath)) {
                return lines.filter(line -> line.startsWith("#") == false) // lines starting with `#` are comments
                    .toList();
            } catch (IOException e) {
                logger.warn(() -> "failed to read file [" + unicastHostsFilePath + "]"; e);
                return Collections.emptyList();
            }
        }

        logger.warn("expected; but did not find; a dynamic hosts list at [{}]"; unicastHostsFilePath);

 

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?