org.apache.lucene.index
public class CheckIndex extends java.lang.Object
As this tool checks every byte in the index, on a large index it can take quite a long time to run.
WARNING: this tool and API is new and experimental and is subject to suddenly change in the next release. Please make a complete backup of your index before using this to fix your index!
Modifier and Type | Class and Description |
---|---|
static class |
CheckIndex.Status
Returned from
checkIndex() detailing the health and status of the index. |
Modifier and Type | Field and Description |
---|---|
static java.io.PrintStream |
out
Deprecated.
Use
setInfoStream(java.io.PrintStream) per instance,
instead. |
Constructor and Description |
---|
CheckIndex(Directory dir)
Create a new CheckIndex on the directory.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
check(Directory dir,
boolean doFix)
Deprecated.
Please instantiate a CheckIndex and then use
checkIndex() instead |
static boolean |
check(Directory dir,
boolean doFix,
java.util.List onlySegments)
Deprecated.
Please instantiate a CheckIndex and then use
checkIndex(List) instead |
CheckIndex.Status |
checkIndex()
Returns a
CheckIndex.Status instance detailing
the state of the index. |
CheckIndex.Status |
checkIndex(java.util.List onlySegments)
Returns a
CheckIndex.Status instance detailing
the state of the index. |
void |
fixIndex(CheckIndex.Status result)
Repairs the index using previously returned result
from
checkIndex() . |
static void |
main(java.lang.String[] args)
Command-line interface to check and fix an index.
|
void |
setInfoStream(java.io.PrintStream out)
Set infoStream where messages should go.
|
public static java.io.PrintStream out
setInfoStream(java.io.PrintStream)
per instance,
instead.public CheckIndex(Directory dir)
public void setInfoStream(java.io.PrintStream out)
public static boolean check(Directory dir, boolean doFix) throws java.io.IOException
checkIndex()
insteadjava.io.IOException
public static boolean check(Directory dir, boolean doFix, java.util.List onlySegments) throws java.io.IOException
checkIndex(List)
insteadjava.io.IOException
public CheckIndex.Status checkIndex() throws java.io.IOException
CheckIndex.Status
instance detailing
the state of the index.
As this method checks every byte in the index, on a large index it can take quite a long time to run.
WARNING: make sure you only call this when the index is not opened by any writer.
java.io.IOException
public CheckIndex.Status checkIndex(java.util.List onlySegments) throws java.io.IOException
CheckIndex.Status
instance detailing
the state of the index.onlySegments
- list of specific segment names to check
As this method checks every byte in the specified segments, on a large index it can take quite a long time to run.
WARNING: make sure you only call this when the index is not opened by any writer.
java.io.IOException
public void fixIndex(CheckIndex.Status result) throws java.io.IOException
checkIndex()
. Note that this does not
remove any of the unreferenced files after it's done;
you must separately open an IndexWriter
, which
deletes unreferenced files when it's created.
WARNING: this writes a new segments file into the index, effectively removing all documents in broken segments from the index. BE CAREFUL.
WARNING: Make sure you only call this when the index is not opened by any writer.
java.io.IOException
public static void main(java.lang.String[] args) throws java.io.IOException, java.lang.InterruptedException
Run it like this:
java -ea:org.apache.lucene... org.apache.lucene.index.CheckIndex pathToIndex [-fix] [-segment X] [-segment Y]
-fix
: actually write a new segments_N file, removing any problematic segments
-segment X
: only check the specified
segment(s). This can be specified multiple times,
to check more than one segment, eg -segment _2
-segment _a
. You can't use this with the -fix
option.
WARNING: -fix
should only be used on an emergency basis as it will cause
documents (perhaps many) to be permanently removed from the index. Always make
a backup copy of your index before running this! Do not run this tool on an index
that is actively being written to. You have been warned!
Run without -fix, this tool will open the index, report version information and report any exceptions it hits and what action it would take if -fix were specified. With -fix, this tool will remove any segments that have issues and write a new segments_N file. This means all documents contained in the affected segments will be removed.
This tool exits with exit code 1 if the index cannot be opened or has any corruption, else 0.
java.io.IOException
java.lang.InterruptedException
Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.