FactorPad
Build a Better Process

The Solr create collection Command Syntax and Examples

This command is used in a distributed search environment using SolrCloud to create collections across multiple shards and replicas. It is one of three commands used to create cores and collections at the command line.
  1. About - understand the purpose of the create collection command.
  2. Syntax - see solr create collection command usage from the command line.
  3. Options - view 6 options used with the solr create collection command.
  4. Examples - review several common examples including additional help.
face pic by Paul Alan Davis, CFA
Updated: February 24, 2021
Here we focus on the command line using a Linux-based operating system, however many of the same commands work for macOS. There are slight differences for Windows.

Outline Back Tip Next

/ factorpad.com / tech / solr / reference / solr-create-collection.html


An ad-free and cookie-free website.


The Solr create collection Command

Beginner

The distributed search space is seeing more competition as developers build applications for their website search and enterprise search needs. The Apache Lucene search libraries sit behind both Apache Solr search and Elasticsearch. These offerings are best suited for those looking to build their own applications. A second option is to use a managed search offering from Google Custom Search or Amazon CloudSearch, among others. It is important for developers to evaluate which offering suits their needs.

Any comprehensive review requires building a test environment which is normally performed on one server in Solr standalone mode. Next, as search volumes increase it is important to review distributed search offerings and in Apache Solr that sits in SolrCloud mode.

Tests in Solr require building data sets and configurations for managing the search application. Here with the solr create_collection command you can create a collection in a test environment in SolrCloud mode.

Apache Solr Reference

1. About the Solr create collection command

The solr create_collection, used in distributed SolrCloud mode, has functionality for setting up shards and replicas. It also is used to set up links to Apache ZooKeeper which manages search traffic and is helpful in failover situations.

Because solr create_collection has added complexity, if your test case is for a standalone mode application then the solr create or solr create_core commands are better suited for you.

The solr create_collection command is one of 12 commands within the main solr script.

The solr create_collection command itself has 6 options, also known as parameters.

2. Syntax for the solr create collection command

The syntax for running solr create_collection is as follows.

$ bin/solr create [-c name] [-d confdir] [-n configName] [-shards or -s #] [-replicationFactor or -rf #] [-p port]

The list of 6 options including default values are explained fully in the table below.

This syntax assumes your current working directory is the $SOLR_HOME directory for Solr, which for version 7 would be ~/solr-7.0.0/ in standalone mode for a local installation. When running in a production environment the directory locations may differ.

So the path to the location of the solr script is: ~/solr-7.0.0/bin/solr. Alternatively the solr script can be run using the convention ./solr from within the bin directory.

When using a Solr Windows installation, the solr script is called using solr.cmd.

3. Options for the solr create collection command

For the solr create_collection command the -c option is required. The other options (parameters) are optional.

Syntax Purpose Default
bin/solr create_collection with only -c <name> input Create a Solr collection with default options named <name>.
  • -c <name>
  • -d <name>
  • -n _default
  • -s 1
  • -rf 1
  • -p 8983
-c <name> Select a name for the collection in SolrCloud mode. -c <name> is required
-d <confdir> Select the configuration directory contents to copy to the collection in SolrCloud mode. Currently two options exist:
  • _default - a basic configuration option
  • sample_techproducts_configs - a more advanced configuration set that can be used with the techproducts example data set provided by Apache.
You can also pass an alternative location using a path, such as /mycustomconfigs. In SolrCloud mode by default the script will create a directory in ZooKeeper and copy the _default configurations that include the lang directory and files:
  • lang
  • managed-schema
  • params.json
  • protwords.txt
  • solrconfig.xml
  • stopwords.txt
  • synonyms.txt
_default
-n <configName> You can select a name for the configuration directory set up by the -d <confdir> option. By default the name selected will match that selected with -c <name> and contents will be copied to it from the _default directory. This option is provided if a desired configuration directory already exists. <name> from the -c option
-shards <#> or -s <#> Set the number of shards to split the collection into. 1
-rf <#> Set the number of copies of each document in the collection. The option can be specified using the long form -replicationFactor <#> as well. 1 (not replicated)
-p <port> Select the port on the server where Solr should create the collection. Solr selects the first running server

4. Examples of the solr create collection command

Example 1 - Create a Solr collection

The following command will create a Solr collection with the name mycollection on the default port 8983.

$ bin/solr create -c mycollection
Example 2 - Create a Solr collection on a non-default port

The following command will create a Solr collection called mycore on port number 8984 instead of the default 8983. This also creates configuration directory called mycollection with a copy of contents from /server/solr/configsets/_default.

$ bin/solr create -c mycollection -p 8984
Example 3 - Create a Solr collection and renaming techproducts configs

The following command will create a Solr collection named mycollection copying the techproducts configuration to a directory called myconfigs.

$ bin/solr create -c mycollection -d sample_techproducts_configs -n myconfigs
Example 4 - Create a Solr collection with 2 shards and 2 replicas

The following command will create a Solr collection named mycollection with 2 shards and 2 replicas using the _default configurations copied and named mycollection.

$ bin/solr create -c mycollection -s 2 -rf 2
Example 5 - Print additional help on the solr create_collection command

From the command line you can access additional help on the solr create_collection command by appending -help after the command.

$ bin/solr create_collection -help

Other Related Solr Content

FactorPad offers Apache Solr Search content in both tutorials and reference.


What's Next?

Watch for more free Apache Solr content on our YouTube Channel. Follow @factorpad at Twitter for reminders.

Outline Back Tip Next

/ factorpad.com / tech / solr / reference / solr-create-collection.html


solr create
apache solr
solr reference
enterprise search
apache Lucene
lucene reference
apache Solr search
solr examples
solrcloud
solr syntax
solr create
solr wiki
solr settings
solr configuration
solr man page

A newly-updated free resource. Connect and refer a friend today.