Failed to read file – How to solve this Elasticsearch error

Opster Team

Aug-23, Version: 6.8-6.8

Briefly, this error occurs when Elasticsearch is unable to read a file due to an incompatible version. This could be because the file was created with a newer version of Elasticsearch than the one currently being used. To resolve this issue, you can upgrade your Elasticsearch to the version that matches the file or recreate the file with the version of Elasticsearch you are currently using. Alternatively, you can use a tool to convert the file to a compatible version.

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

Log Context

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

     private List readFileContents(Path path) {
        try (Stream lines = Files.lines(path)) {
            return lines.filter(line -> line.startsWith("#") == false) // lines starting with `#` are comments
                .collect(Collectors.toList());
        } catch (IOException e) {
            logger.warn(() -> new ParameterizedMessage("failed to read file [{}]"; unicastHostsFilePath); e);
            return Collections.emptyList();
        }
    }

    
Override



 

 [ratemypost]