In general one would use {@link IndexUpgrader}, but for a fully customizeable upgrade, you can use this like any other {@code MergePolicy} and call {@link IndexWriter#optimize()}:
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_XX, new KeywordAnalyzer()); iwc.setMergePolicy(new UpgradeIndexMergePolicy(iwc.getMergePolicy())); IndexWriter w = new IndexWriter(dir, iwc); w.optimize(); w.close();
Warning: This merge policy may reorder documents if the index was partially upgraded before calling optimize (e.g., documents were added). If your application relies on "monotonicity" of doc IDs (which means that the order in which the documents were added to the index is preserved), do a full optimize instead. Please note, the delegate {@code MergePolicy} may also reorder documents. @lucene.experimental @see IndexUpgrader
|
|