solr Merging Indexes

  categories:搜索资料  tags:,   author:




if you need to combine indexes from two different projects or from multiple servers previously used in a distributed configuration, you can use either the IndexMergeTool included in lucene-misc or the CoreAdminHandler.

To merge indexes, they must meet these requirements:

  • The two indexes must be compatible: their schemas should include the same fields and they should analyze fields the same way.
  • The indexes must not include duplicate data.

Optimally, the two indexes should be built using the same schema.

Using IndexMergeTool

To merge the indexes, do the following:

  1. Find the lucene-core and lucene-misc JAR files that your version of Solr is using. You can do this by copying your solr.war file somewhere and unpacking it (jar xvf solr.war). These two JAR files should be in WEB-INF/lib. They are probably called something like lucene-core-VERSION.jar and lucene-misc-VERSION.jar.
  2. Copy them somewhere easy to find.
  3. Make sure that both indexes you want to merge are closed.
  4. Issue this command:
    java -cp /path/to/lucene-core-VERSION.jar:/path/to/lucene-misc-VERSION.jar

    This will create a new index at /path/to/newindex that contains both index1 and index2.

  5. Copy this new directory to the location of your application’s solr index (move the old one aside first, of course) and start Solr.For example:
    java -cp /tmp/lucene-core-4.4.0.jar:
    /tmp/lucene-misc-4.4.0.jar org/apache/lucene/misc/IndexMergeTool

Using CoreAdmin

This method uses the CoreAdminHandler with either the indexDir or srcCore parameters.

The indexDir parameter is used to define the path to the indexes for the cores that should be merged, and merge them into a 3rd core that must already exist prior to initiation of the merge process. The indexes must exist on the disk of the Solr host, which may make using this in a distributed environment cumbersome. With the indexDir parameter, a commit should be called on the cores to be merged (so the IndexWriter will close), and no writes should be allowed on either core until the merge is complete. If writes are allowed, corruption may occur on the merged index. Once complete, a commit should be called on the merged core to make sure the changes are visible to searchers.

The following example shows how to construct the merge command with indexDir:


In this example, core is the new core that is created prior to calling the merge process.

The srcCore parameter is used to call the cores to be merged by name instead of defining the path. The cores do not need to exist on the same disk as the Solr host, and the merged core does not need to exist prior to issuing the command. srcCore also protects against corruption during creation of the merged core index, so writes are still possible while the merge occurs. However, srcCore can only merge Solr Cores – indexes built directly with Lucene should be merged with either the IndexMergeTool or the indexDir parameter.

The following example shows how to construct the merge command with srcCore:


Combining Distribution and ReplicationLegacy Scaling and Distribution

快乐成长 每天进步一点点