Package org.apache.lucene.index

# Class IndexUpgrader

java.lang.Object
org.apache.lucene.index.IndexUpgrader

public final class IndexUpgrader extends Object
This is an easy-to-use tool that upgrades all segments of an index from previous Lucene versions to the current segment file format. It can be used from command line:

      java -cp lucene-core.jar org.apache.lucene.index.IndexUpgrader [-delete-prior-commits] [-verbose] indexDir

Alternatively this class can be instantiated and `upgrade()` invoked. It uses `UpgradeIndexMergePolicy` and triggers the upgrade via an forceMerge request to `IndexWriter`.

This tool keeps only the last commit in an index; for this reason, if the incoming index has more than one commit, the tool refuses to run by default. Specify `-delete-prior-commits` to override this, allowing the tool to delete all but the last commit. From Java code this can be enabled by passing `true` to `IndexUpgrader(Directory,InfoStream,boolean)`.

Warning: This tool may reorder documents if the index was partially upgraded before execution (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 forceMerge instead. The `MergePolicy` set by `IndexWriterConfig` may also reorder documents.

## Constructor Summary

Constructors
Constructor
Description
`IndexUpgrader(Directory dir)`
Creates index upgrader on the given directory, using an `IndexWriter` using the given `matchVersion`.
`IndexUpgrader(Directory dir, IndexWriterConfig iwc, boolean deletePriorCommits)`
Creates index upgrader on the given directory, using an `IndexWriter` using the given config.
`IndexUpgrader(Directory dir, InfoStream infoStream, boolean deletePriorCommits)`
Creates index upgrader on the given directory, using an `IndexWriter` using the given `matchVersion`.

## Method Summary

Modifier and Type
Method
Description
`static void`
`main(String[] args)`
Main method to run {code IndexUpgrader} from the command-line.
`void`
`upgrade()`
Perform the upgrade.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### IndexUpgrader

public IndexUpgrader(Directory dir)
Creates index upgrader on the given directory, using an `IndexWriter` using the given `matchVersion`. The tool refuses to upgrade indexes with multiple commit points.

### IndexUpgrader

public IndexUpgrader(Directory dir, InfoStream infoStream, boolean deletePriorCommits)
Creates index upgrader on the given directory, using an `IndexWriter` using the given `matchVersion`. You have the possibility to upgrade indexes with multiple commit points by removing all older ones. If `infoStream` is not `null`, all logging output will be sent to this stream.

### IndexUpgrader

public IndexUpgrader(Directory dir, IndexWriterConfig iwc, boolean deletePriorCommits)
Creates index upgrader on the given directory, using an `IndexWriter` using the given config. You have the possibility to upgrade indexes with multiple commit points by removing all older ones.

## Method Details

### main

public static void main(String[] args) throws IOException
Main method to run {code IndexUpgrader} from the command-line.

Throws:
  `IOException`

### upgrade

public void upgrade() throws IOException
Perform the upgrade.

Throws:
  `IOException`