Updated on 2024-11-29 GMT+08:00

Shell Client Operation Commands

Before using the Solr shell script, you need to install the Solr client.

Operation Commands of the Solr Configuration Set

Operation

Command

Parameter

Example

Generating a Solr configuration set in a specified local path

solrctl confset --generate path [_default | -confWithHBase | -confWithHDFS | -confWithDisk | -confWithSchema ]

  • generate is a command used to generate a configuration set in a specified path.
  • path indicates the local path of the client.
  • The parameters in [_default | -confWithHBase | -confWithHDFS | -confWithDisk ] are optional. The _default parameter indicates that a configuration set in _default mode is generated. The -confWithHBase parameter indicates that a configuration set that supports HBase full-text index is generated. The -confWithHDFS parameter indicates that a configuration set that supports index data storage in HDFS is generated. The -confWithDisk parameter indicates that a configuration set that supports index data storage on local disks is generated. The -confWithSchema parameter indicates that a configuration set that supports data storage on HDFS or local disks based on the value of INDEX_STORED_ON_HDFS is generated.
    NOTE:
    • If a user other than root is used to run the command, the user must have the corresponding permission on the local directory.
    • To modify the INDEX_STORED_ON_HDFS parameter, log in to FusionInsight Manager, choose Cluster > Services > Solr, click Configurations then All Configurations, and search for INDEX_STORED_ON_HDFS.

solrctl confset --generate /home/solrDir or solrctl confset --generate /home/solrDir -schemaless or solrctl confset --generate /home/solrDir -confWithHBase or solrctl confset --generate /home/solrDir -confWithHDFS or solrctl confset --generate /home/solrDir -confWithDisk or solrctl confset --generate /home/solrDir _default

Uploading the local configuration file set to ZooKeeper, and specifying the name

solrctl confset --create name path -force

  • create is a command used to upload files in a configuration set.
  • name identifies the Solr configuration set to be uploaded to ZooKeeper.
  • path indicates the local path of the client.
  • -force is optional, indicating that the configuration set can still be uploaded without schema.xml and solrconfig.xml files.

solrctl confset --create myconf /home/solrDir/

Updating the Solr configuration set

solrctl confset --update name path -force

  • update is a command used to update a configuration file set.
  • name indicates the configuration set to be updated.
  • path indicates the local path of the client.
  • -force is optional, indicating that the configuration set can still be updated without schema.xml and solrconfig.xml files.

solrctl confset --update myconf /home/solrDir/

Obtaining the Solr configuration set and saving it to the local client

solrctl confset --get name path

  • get is a command used to obtain a configuration set.
  • name indicates the configuration set to be obtained.
  • path indicates the local path of the client.

solrctl confset --get myconf /home/solrTest/

Uploading a file to the specified path on ZooKeeper

solrctl confset --putfile path localpath

  • putfile is a command used to upload a file.
  • path indicates the path to which the file is uploaded on ZooKeeper.
  • localpath indicates the local file save path.

solrctl confset --putfile /configs/confWithSchema/test.xml /opt/test.xml

Obtaining a file of the specified path in the configuration set and save it to a local node

solrctl confset --getfile path filename

  • getfile is a command used to obtain a file.
  • path indicates the file save path on ZooKeeper.
  • filename indicates the file name.

solrctl confset --getfile /configs/confWithSchema/schema.xml schema.xml

Deleting a file in the specified path

solrctl confset --clearfile path

  • clearfile is a command used to delete a file.
  • path indicates the file path.

solrctl confset --clearfile /configs/confWithSchema/test.xml

Deleting the specified configuration set

solrctl confset --delete name

  • delete is a command used to delete the specified configuration file set.
  • name indicates the name of the configuration set to be deleted.

solrctl confset --delete myconf

Listing the Solr configuration sets

solrctl confset --list

list is a command used to list the configuration sets.

solrctl confset --list

  • When you use the solrctl confset --get name path command to obtain a Solr file of a configuration set from ZooKeeper, a conf folder is generated in the specified path. The conf directory stores the configuration files, including schema.xml and solrconfig.xml.
  • When you run the command to delete a configuration set, enter y as prompted to confirm the deletion.

Collection Operation Commands

Operation

Command

Parameter

Example

Creating a collection

solrctl collection --create name

[-s <numShards>]

[-a Create collection with autoAddReplicas=true]

[-S <true|false> Create collection true or false with sharedFsReplication]

[-b <true|false> Create collection true or false with autoShardBalance]

[-c <collection.configName>]

[-r <replicationFactor>]

[-m <maxShardsPerNode>]

[-n <createNodeSet>]

[-f <router.field>]

[-p name=value ...]

  • create is a command used to create a collection.
  • name indicates the collection name.
  • -s numShards indicates the number of shards in a collection.
  • -a indicates whether to enable the auto copy addition function.
  • -S indicates whether to enable the single-copy storage mode. true indicates that the mode is enabled and only nodes that support shared storage are used. false indicates that only local storage is used.
  • -b indicates whether to enable the auto shard load balancing function.
  • -c collection.configName indicates the specified configuration file used to create the collection. Use the created configuration file in the real-world production environment. The template configuration file is restored after the Solr service restarts.
  • -r replicationFactor indicates the number of replicas specified for each shard when a collection is created. The value does not change though replicas are added or deleted.
  • -m maxShardsPerNode indicates the maximum number of shards on each node.
  • -n createNodeSet indicates the node on which a collection is created.
  • -f router.field indicates the field for hash.
  • -p indicates the extended key-value pair to create a collection.

solrctl collection --create collectionTest -c myconf -s 3 -r 1 -m 1 -n solrIp1:port1_solr,solrIp2:port2_solr,solrIp3:port3_solr

Modifying a collection

solrctl collection --modify name

[-a <true|false> Modify collection true or false with autoAddReplicas]

[-b <true|false> Modify collection true or false with autoShardBalance]

[-r <replicationFactor>] [-m <maxShardsPerNode>]

  • -a indicates whether to enable the auto copy addition function.
  • -b indicates whether to enable the auto shard load balancing function.
  • -r indicates the number of replicas.
  • -m indicates the maximum number of shards on each node.

solrctl collection --modify collectionTest -b true

Deleting a collection

solrctl collection --delete name

  • delete is a command used to delete a collection.
  • name indicates the name of the collection to be deleted.

solrctl collection --delete collectionTest

Reloading a collection

solrctl collection --reload name

  • reload is a command used to reload a collection.
  • name indicates the name of a collection to be reloaded.

solrctl collection --reload collection1

Splitting a shard of a collection

solrctl collection --splitshard collection shard

[-async <async task id>]

  • splitshard is a command used to split a shard of a collection.
  • collection indicates the name of the collection where shards need to be split.
  • shard indicates the name of the shard to be split.
  • -async indicates the ID of the asynchronous task to be executed.
NOTE:

The async parameter must be specified. Tasks are asynchronously executed on the server. You can run the requeststatus command to query the task status. Different values of the async parameter must be specified for each task.

solrctl collection --splitshard collection1 shard1 -async 1

Adding a shard to a collection

solrctl collection --createshard collection shard

  • createshard is a command used to add a shard to a collection.
  • collection indicates the name of a collection to which a shard is added.
  • shard indicates the name of the shard to be added.
    NOTE:

    shards can be added only to collections with router.name=implicit specified.

solrctl collection --createshard collection1 shard1

Deleting a shard from a collection

solrctl collection --deleteshard collection shard

  • deleteshard is a command used to delete a shard from a collection.
  • collection indicates a collection from which a shard is deleted.
  • shard indicates the shard to be deleted.

solrctl collection --deleteshard collection1 shard1

Creating an alias for a collection

solrctl collection --createalias aliasname collections

  • createalias is a command used to create an alias for a collection.
  • aliasname indicates the alias of a collection.
  • collections identifies the collection for which an alias is created.

solrctl collection --createalias mycollection collections1

Deleting the alias of a collection

solrctl collection --deletealias aliasname

  • deletealias is a command used to delete the alias of a collection.
  • aliasname indicates the alias of a collection.

solrctl collection --deletealias mycollection

Deleting the replica of a collection

solrctl collection --deletereplica [-p name=value]...

  • deletereplica is a command used to delete a replica of a collection.
  • -p indicates a key-value pair.
    NOTE:

    You need to specify the collection and shard to which a replica belongs and name of the replica to be deleted.

solrctl collection --deletereplica -p collection=collection1 -p shard=shard1 -p replica=core_node2

Adding a replica to a collection

solrctl collection --addreplica [-p name=value]...

  • addreplica is a command used to add a replica to a collection.
  • -p indicates a key-value pair.
NOTE:

You need to specify the collection and shard to which the replica belongs.

solrctl collection --addreplica -p collection=collection1 -p shard=shard1 -p node=192.168.0.22:21101_solr

Deleting the index data of a collection

solrctl collection --deletedocs name

  • deletedocs is a command used to delete the index data.
  • name indicates the collection whose data is to be deleted.

solrctl collection --deletedocs collection1

Listing all collections

solrctl collection --list

list is a command used to list all collections.

solrctl collection --list

Querying the cluster status

solrctl collection --clusterstatus

clusterstatus indicates the cluster status.

solrctl collection --clusterstatus

Obtaining the status and statistics of overseer

solrctl collection --overseerstatus

overseerstatus indicates the overseer status and statistics.

solrctl collection --overseerstatus

Migrating all replicas from the source SolrServer instance to the target one

solrctl collection --replacenode source_node target_node

[-async <async task id>]

[-p Replace node with parallel=true]

[-t <timeout in s>]

[-c Replace node with skipCheck=false]

[-sotimeout <socket timeout in ms>]

  • replacenode migrates all replicas from the source SolrServer instance to the target one.
  • source_node indicates the source SolrServer instance from which the replicas are migrated.
  • target_node indicates the target SolrServer instance to which the replicas are migrated.
  • -async indicates the ID of the asynchronous task to be executed.
    NOTE:

    The async parameter must be specified. Tasks are asynchronously executed on the server. You can run the requeststatus command to query the task status. Different values of the async parameter must be specified for each task.

  • -p: It is an optional parameter. When this parameter is specified, all replicas are moved to the target SolrServer concurrently. If replicas on the source SolrServer instance have a large number of indexes, network and disk I/O loads will be high.
  • -t is an optional parameter. It Specifies the timeout interval for the collection to wait for the shard to become active after the destination instance is successfully created during instance migration. The unit is second. The default value is 600s, that is, 10 minutes. This parameter cannot be used to specify the timeout interval for creating a collection. The default timeout interval for creating a collection is 3 minutes.
  • -c is an optional parameter. If this parameter is specified, Solr checks whether more than two replicas exist in the same shard of the same collection on the host where the target SolrServer instance resides after migration.
  • -sotimeout is an optional parameter. It specifies the timeout interval for the Solr server to migrate data during instance migration. The unit is ms. The default value is 600,000 ms, that is, 10 minutes.

solrctl collection --replacenode 192.168.229.137:21101_solr 192.168.229.219:21104_solr

-async 2

Querying the asynchronous task execution status

solrctl collection --requeststatus requestid

requestid is the ID of the asynchronous task to be queried.

NOTE:

If the value of msg is found [requestid] in running tasks in the query result, the task is being executed.

If the value is found [requestid] in completed tasks, the task is complete.

solrctl collection --requeststatus 1

  • If the schema.xml configuration set file is incorrectly configured, the collection may fail to be created and junk data remains. In this case, you need to manually clear the junk data under the index data save path of the collection in each instance, remove the /solr/clusterstate.json file from ZooKeeper, and restart Solr. You are advised to create a collection with a single shard and check whether the configuration is correct after configuring the schema.xml file.
  • When the Solr index data is stored in HDFS, you can set the number of index data replicas by modifying <int name="solr.hdfs.replication.number">${solr.hdfs.replication.number:3}</int> in the solrconfig.xml file. The default value is 3. In addition, you can set the number of tlog replicas by modifying <int name="tlogDfsReplication">${solr.ulog.tlogDfsReplication:3}</int> in the solrconfig.xml file. The default value is 3.
  • When you run commands to delete collections, shards, aliases, replicas, and data, enter y as prompted to confirm the deletion.

Cluster Operation Commands

Operation

Command

Parameter

Example

Obtaining the solr.xml file

solrctl cluster --get-solrxml file

  • get-solrxml is a command used to obtain the solr.xml file.
  • file identifies the local path where the solr.xml file is saved.

solrctl cluster --get-solrxml /opt/client/solrtest.xml

Upload the solr.xml file:

solrctl cluster --put-solrxml file

  • put-solrxml is a command used to upload the solr.xml file.
  • file identifies the local path where the solr.xml file is saved.

solrctl cluster --put-solrxml /opt/client/solrtest.xml

Setting properties in clusterprops.

solrctl cluster --set-property name value

  • set-property is a command used to set properties in clusterprops.
  • name indicates the updated property name.
  • value indicates the updated property value.

solrctl cluster --set-property urlScheme http

Removing specified properties from clusterprops

solrctl cluster --remove-property name

  • remove-property is a command to remove specified properties from clusterprops.
  • name indicates the name of the property to be removed.

solrctl cluster --remove-property urlScheme

Displaying a list of idle nodes

solrctl cluster --list-free-node

list-free-node is a command used to provide a list of idle nodes.

solrctl cluster --list-free-node

Displaying a list of active nodes supporting local disks

solrctl cluster --list-local-disk-live-node

list-local-disk-live-node is a command used to provide a list of active nodes supporting local disks.

solrctl cluster --list-local-disk-live-node

Displaying information about the state.json file of a collection

solrctl cluster --get-coll-state or

solrctl cluster --get-coll-state collection

  • get-coll-state is a command used to display information about the state.json file of all collections.
  • get-coll-state collection is a command used to display information about the state.json file of a collection.

solrctl cluster --get-coll-state or

solrctl cluster --get-coll-state collection1

Displaying information about all Solr instances

solrctl cluster --list-node

list-node indicates that information about all Solr instances are displayed.

solrctl cluster --list-node

Displaying information about all Solr instances

solrctl cluster --list-live-node

list-live-node indicates that information about all live Solr instances are displayed.

solrctl cluster --list-live-node

The --list-free-node command is used to query the nodes that can be securely decommissioned when Solr is out of service.

HBaseIndexer Operation Commands

Operation

Command

Parameter

Example

Viewing the status of the newly created indexers

hbase-indexer list-indexers

list-indexers indicates the status of the newly created indexers can be viewed.

hbase-indexer list-indexers

Deleting the created indexers

hbase-indexer delete-indexer -n indexer_name

  • delete-indexer indicates the created indexers to be deleted.
  • indexer_name indicates the name of the indexer to be deleted.

hbase-indexer delete-indexer -n userIndexer

Creating an indexer

hbase-indexer add-indexer -n indexer_name -c path/index.xml -cp solr.collection=collection_name -cp solr.zk=hostips:zkport/solr

  • add-indexer is a command used to create an indexer.
  • indexer_name is a command used to indicate the name of an indexer to be created.
  • path/index.xml is the absolute path of the configuration file for setting the mappings between Solr indexes and HBase lists.
  • solr.collection indicates the name of the collection corresponding to an indexer.
  • solr.zk is the Solr path on ZooKeeper.

hbase-indexer add-indexer -n userIndexer -c /opt/client/Solr/hbase-indexer/conf/hbase-demo-indexer.xml -cp solr.collection=collection1 -cp solr.zk=192.168.1.1:2181,192.168.1.2:2181,192.168.1.3:2181/solr

Creating an index task

hbase-indexer batch-indexer --hbase-indexer-zk hostip:zkport --hbase-indexer-name indexer_name --out-put-dir hdfs_url --go-live --overwrite-output-dir --verbose --reducers number --zk-host hostip:zkport/solr --rowkey-dir hdfs_url --hbase-indexer-file configfilepath

  • batch-indexer is a command used to create an index task.
  • --hbase-indexer-zk indicates the ZooKeeper information.
  • --hbase-indexer-name indicates the name of an existing indexer.
  • --output-dir is an optional parameter and indicates the output directory of MapReduce jobs.
  • --go-live is an optional parameter and indicates whether to merge collection data to the Solr cluster. If this parameter is not specified, the created collection cannot be queried in Solr.
  • --overwrite-output-dir is an optional parameter that indicates whether to reuse the HDFS directory.
  • --verbose is an optional parameter and indicates whether to output detailed information.
  • --reducers indicates the number of reducers used in MapReduce jobs and needs to be consistent with the number of shards.
  • --zk-host is an optional parameter and indicates the Solr path on ZooKeeper.
  • --rowkey-dir is an optional parameter and indicates the rowkey save path and is used in incremental indexes.
  • --hbase-indexer-file is an optional parameter. When the HBase multi-instance function is enabled, set this parameter and other related configuration items. For details, see section "Solr over HBase".

hbase-indexer batch-indexer --hbase-indexer-zk 192.168.1.1:2181,192.168.1.2:2181,192.168.1.3:2181 --hbase-indexer-name userIndexer --output-dir hdfs://hacluster/user/solr/test --go-live --overwrite-output-dir --verbose --reducers 10 --zk-host 192.168.1.1:2181,192.168.1.2:2181,192.168.1.3:2181/solr --rowkey-dir hdfs://hacluster/user/solr/rowkey --hbase-indexer-file /opt/client/Solr/hbase-indexer/conf/user.xml

Checking the collection task status in real time

hbase-indexer replication-status -z hostip:zkport --hbase-instance-file configfile_uri --enable-jmx

  • replication-status is a command used to check the collection task status in real time.
  • -z indicates ZooKeeper information.
  • --hbase-instance-file indicates the absolute path of configuration files of HBase instances.
  • --enable-jmx is an optional parameter. If you want to use JMX to monitor the HBase RegionServer, the following content must be added to RegionServer startup parameters:-Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=remote_port (The default value is 21146.)

hbase-indexer replication-status -z 192.168.1.1:2181 --hbase-instance-file /opt/client/Solr/hbase-indexer/conf/hbase-site.xml --enable-jmx

In a cluster in security mode, if you want to run the hbase-indexer replication-status command, perform authentication as user hbase.