CoreAdminHandler Parameters and Usage

The CoreAdminHandler is a special SolrRequestHandler that is used to manage Solr cores. Unlike normal SolrRequestHandlers, the CoreAdminHandler is not attached to a single core. Instead, it manages all the cores running in a single Solr instance. Only one CoreAdminHandler exists for each top-level Solr instance.

To use the CoreAdminHandler, make sure that the adminPath attribute is defined on the <cores> element; otherwise you will not be able to make HTTP requests to perform Solr core administration.

The CoreAdminHandler supports seven different actions that may be invoked on the adminPath URL. The action to perform is named by the HTTP request parameter "action", with arguments for a specific action being provided as additional parameters.

All action names are uppercase. The action names are:

  • STATUS
  • CREATE
  • RELOAD
  • RENAME
  • SWAP
  • UNLOAD
  • MERGEINDEXES
  • SPLIT

These actions are described in detail in the sections below.

STATUS

The STATUS action returns the status of all running Solr cores, or status for only the named core.

http://localhost:8983/solr/admin/cores?action=STATUS

http://localhost:8983/solr/admin/cores?action=STATUS&core=core0

The STATUS action accepts one optional parameter:

ParameterDescription
core(Optional) The name of a core, as listed in the "name" attribute of a <core> element in solr.xml.
indexInfoIf false, information about the index will not be returned with a core STATUS request. In Solr implementations with a large number of cores (i.e., more than hundreds), retrieving the index information for each core can take a lot of time and isn't always required.

CREATE

The CREATE action creates a new core and registers it. If persistence is enabled (persistent="true" on the <solr> element), the updated configuration for this new core will be saved in solr.xml. If a Solr core with the given name already exists, it will continue to handle requests while the new core is initializing. When the new core is ready, it will take new requests and the old core will be unloaded.

http://localhost:8983/solr/admin/cores?action=CREATE&name=coreX&instanceDir=path/to/dir&config=config_file_name.xml&schema=schem_file_name.xml&dataDir=data

The CREATE accepts the two mandatory parameters, as well as five optional parameters.

ParameterDescription
nameThe name of the new core. Same as "name" on the <core> element.
instanceDirThe directory where files for this SolrCore should be stored. Same as instanceDir on the <core> element.
config(Optional) Name of the config file (solrconfig.xml) relative to instanceDir.
schema(Optional) Name of the schema file (schema.xml) relative to instanceDir.
datadir(Optional) Name of the data directory relative to instanceDir.
collection(Optional) The name of the collection to which this core belongs. The default is the name of the core. collection.<param>=<value> causes a property of <param>=<value> to be set if a new collection is being created. Use collection.configName=<configname> to point to the configuration for a new collection.
shard(Optional) The shard id this core represents. Normally you want to be auto-assigned a shard id.

Use collection.configName=<configname> to point to the config for a new collection.

For example: curl 'http://localhost:8983/solr/admin/cores?action=CREATE&name=mycore&collection=collection1&shard=shard2'

RELOAD

The RELOAD action loads a new core from the configuration of an existing, registered Solr core. While the new core is initializing, the existing one will continue to handle requests. When the new Solr core is ready, it takes over and the old core is unloaded.

This is useful when you've made changes to a Solr core's configuration on disk, such as adding new field definitions. Calling the RELOAD action lets you apply the new configuration without having to restart the Web container.  However the Core Container does not persist the SolrCloud solr.xml parameters, such as solr/@zkHost and solr/cores/@hostPort, which are ignored.

http://localhost:8983/solr/admin/cores?action=RELOAD&core=core0

The RELOAD action accepts a single parameter, core, which is the name of the core to be reloaded.

As of Solr 4.0, REALOAD performs "live" reloads of SolrCore, reusing some existing objects. Some configuration options, such as the DataDir location and IndexWriter related settings in solrconfig.xml can not be changed and made active with a simple RELOAD action.

RENAME

The RENAME action changes the name of a Solr core.

http://localhost:8983/solr/admin/cores?action=RENAME&core=core0&other=core5

The RENAME action requires the following two parameter:

ParameterDescription
coreThe name of the Solr core to be renamed.
otherThe new name for the Solr core. If the persistent attribute of <solr> is true, the new name will be written to solr.xml as the name attribute of the <core> attribute.

SWAP

SWAP atomically swaps the names used to access two existing Solr cores. This can be used to swap new content into production. The prior core remains available and can be swapped back, if necessary. Each core will be known by the name of the other, after the swap.

http://localhost:8983/solr/admin/cores?action=SWAP&core=core1&other=core0

Do not use SWAP with a SolrCloud node. It is not supported and can result in the core being unusable.

The SWAP action requires two parameters, which are described in the table below.

ParameterDescription
coreThe name of one of the cores to be swapped.
otherThe name of one of the cores to be swapped.

UNLOAD

The UNLOAD action removes a core from Solr. Active requests will continue to be processed, but no new requests will be sent to the named core. If a core is registered under more than one name, only the given name is removed.

http://localhost:8983/solr/admin/cores?action=UNLOAD&core=core0

The UNLOAD action requires a parameter (core) identifying the core to be removed. If the persistent attribute of <solr> is set to true, the <core> element with this name attribute will be removed from solr.xml.

Unloading all cores in a SolrCloud collection causes the removal of that collection's metadata from ZooKeeper.

There are three parameters that can be used with the UNLOAD action:

  • deleteIndex: if true, will remove the index when unloading the core.
  • deleteDataDir: if true, removes the data directory and all sub-directories.
  • deleteInstanceDir: if true, removes everything related to the core, including the index directory, configuration files, and other related files.

MERGEINDEXES

The MERGEINDEXES action merges one or more indexes to another index. The indexes must have completed commits, and should be locked against writes until the merge is complete or the resulting merged index may become corrupted. The target core index must already exist and have a compatible schema with the one or more indexes that will be merged to it. Another commit on the target core should also be performed after the merge is complete.

http://localhost:8983/solr/admin/cores?action=MERGEINDEXES&core=core0&indexDir=/opt/solr/core1/data/index&indexDir=/opt/solr/core2/data/index

In this example, we use the indexDir parameter to define the index locations of the source cores. The core parameter defines the target index. A benefit of this approach is that we can merge any Lucene-based index that may not be associated with a Solr core.

Alternatively, we can instead use a srcCore parameter, as in this example:

http://localhost:8983/solr/admin/cores?action=mergeindexes&core=core0&srcCore=core1&srcCore=core2

This approach allows us to define cores that may not have an index path that is on the same physical server as the target core. However, we can only use Solr cores as the source indexes. Another benefit of this approach is that we don't have as high a risk for corruption if writes occur in parallel with the source index.

SPLIT

The SPLIT action splits an index into two or more indexes. The index being split can continue to handle requests. The split pieces can be placed into a specified directory on the server's filesystem or it can be merged into running Solr cores.

The SPLIT action supports three parameters, which are described in the table below.

ParameterDescriptionMulti-valued
coreThe name of the core to be split.false
pathThe directory path in which a piece of the index will be written.true
targetCoreThe target Solr core to which a piece of the index will be mergedtrue
Either path or targetCore parameter must be specified but not both.

The core index will be split into as many pieces as the number of path or targetCore parameters.

http://localhost:8983/solr/admin/cores?action=SPLIT&core=core0&targetCore=core1&targetCore=core2

This example shows the usage of this action with two targetCore parameters. Here the core index will be split into two pieces and merged into the two targetCore indexes.

http://localhost:8983/solr/admin/cores?action=SPLIT&core=core0&path=/path/to/index/1&path=/path/to/index/2

This example shows the usage of this action with two path parameters. The core index will be split into two pieces and written into the two directory paths specified.

The targetCore must already exist and must have a compatible schema with the core index. A commit is automatically called on the core index before it is split.

This command is used as part of the SPLITSHARD command but it can be used for non-cloud Solr cores as well. When used against a non-cloud core, this action will split the source index and distribute its documents alternately so that each split piece contains an equal number of documents.

 

Moving to the New solr.xml FormatSolr Cores and solr.xml

发表评论