If it is only reading, it should be possible, assuming you have the lucene-backwards-codecs in your classpath.
Directory directory = FSDirectory.open(Paths.get(INDEX_PATH));
IndexCommit commit = DirectoryReader.listCommits(directory).getLast();
DirectoryReader reader = DirectoryReader.open(commit, 0, null);
The 0
is the minimum major version to check against. It is better to know which version of Lucene made the index and use that, but 0
is a catch-all.
If things have changed too much, there isn't a guarantee that you can read the index. Lucene only officially supports N-1 codecs, but this method is specifically for this case. Annoyingly, there isn't an IndexWriter
equivalent to lazily reading in the very old and writing in the new.