• Home
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • Maven
  • About
Apache Solr | create_collection command
  1. Notes
  2. create_collection command help
  3. Create a collection using an existing Solr configuration in ZooKeeper
  4. Create a collection + using/uploading to ZooKeeper the default Solr configuration
  5. Create a collection + uploading to ZooKeeper a custom Solr configuration (configuration directory)
  6. Create a collection + uploading to ZooKeeper a custom Solr configuration (custom path)
  7. Create a collection + uploading to ZooKeeper the default Solr configuration + overriding the default name of the Solr configuration in ZooKeeper
  8. Create a collection with 2 shards and 2 replicas (copies)

  1. Notes
    See this page for more details on how to upload Solr configuration to ZooKeeper: Uploading Solr configuration in ZooKeeper

    See this page for more details on how to Install and configure a Solr Cluster: SolrCloud: Cluster

  2. create_collection command help
    $ ${SOLR_ROOT}/bin/solr create_collection -help
    Usage: solr create_collection [-c collectionName] [-n configName] [-d configDir] [-shards #] [-replicationFactor #] [-p port] [-V]
    
    -c collectionName
      Name of the collection to create.
    
    -n configName
      Name of the configuration directory in ZooKeeper.
      By default, if this option is not specified, the configuration will be uploaded to ZooKeeper using the collection name.
    
    -d configDir
      Configuration directory to copy when creating the new collection:
    
      Built-in options are:
      ► _default: Minimal Solr configuration, which supports enabling/disabling field-guessing support.
      ► sample_techproducts_configs: Example configuration with many optional features enabled to demonstrate the full power of Solr
    
      If not specified, default is: _default
    
      Alternatively, you can pass the path to your own configuration directory instead of using one of the built-in configurations,
      such as: bin\solr create_collection -c mycoll -d /tmp/myconfig
    
      By default the script will upload the specified confdir directory into Zookeeper using the same name as the collection (-c) option.
      Alternatively, if you want to reuse an existing directory or create a confdir in Zookeeper that can be shared by multiple collections, use the -n option.
    
    -shards #
      Number of shards to split the collection into.
      Default: 1
    
    -replicationFactor #
      Number of copies of each document in the collection.
      Default: 1 (no replication)
    
    -p port
      Port of a local Solr instance where you want to create the new collection.
      If not specified, the script will search the local system for a running Solr instance and will use the port of the first server it finds.
    
    -V
      Enables more verbose output.
  3. Create a collection using an existing Solr configuration in ZooKeeper
    Create the collection:
    $ ${SOLR_ROOT}/bin/solr create_collection -c collection1 -n solr_config1

    Output:
    Re-using existing configuration directory solr_config1
    Created collection 'collection1' with 1 shard(s), 1 replica(s) with config-set 'solr_config1'

    Notes:
    • If the configuration "solr_config1" doesn't exist (it wasn't created/uploaded to ZooKeeper), Solr will then try to create a new configuration with the name "solr_config1" by using the configuration "_default". You will get the following output:
      Created collection 'collection1' with 1 shard(s), 1 replica(s) with config-set 'solr_config1'

      Note that even if the collection will use an existing Solr configuration in ZooKeeper, the "${SOLR_HOME}/configsets/_default" directory must exist, otherwise you will get this error: Specified configuration directory _default not found!

    • You can verify that the collection was created in ZooKeeper:
      $ ${SOLR_ROOT}/server/scripts/cloud-scripts/zkcli.sh \
      -zkhost "localhost:2181/solr" \
      -cmd ls /collections
  4. Create a collection + using/uploading to ZooKeeper the default Solr configuration
    If you don't specify a Solr configuration when creating a collection, Solr will create a new configuration with the name of the collection.
    Solr will use the default configuration "_default" ("${SOLR_HOME}/configsets/_default").

    Create the collection:
    $ ${SOLR_ROOT}/bin/solr create_collection -c collection2

    Output:
    WARNING: Using _default configset with data driven schema functionality.
    NOT RECOMMENDED for production use.
    To turn off: bin/solr config -c collection2 -p 8984 -action set-user-property -property update.autoCreateFields -value false
    Created collection 'collection2' with 1 shard(s), 1 replica(s) with config-set 'collection2'

    Notes:
    You can verify that the configuration "collection2" is created in ZooKeeper:
    $ ${SOLR_ROOT}/server/scripts/cloud-scripts/zkcli.sh \
    -zkhost "localhost:2181/solr" \
    -cmd ls /configs

    You can verify that the collection "collection2" is created in ZooKeeper:
    $ ${SOLR_ROOT}/server/scripts/cloud-scripts/zkcli.sh \
    -zkhost "localhost:2181/solr" \
    -cmd ls /collections
  5. Create a collection + uploading to ZooKeeper a custom Solr configuration (configuration directory)
    You can create a collection and specify a name of a Solr configuration directory (using the parameter "-d DIRECTORY_NAME") that will be used to create and upload the Solr configuration to ZooKeeper.

    You can choose one of the following directories names that can be found under (${SOLR_HOME}/configsets/):
    ► _default
    ► sample_techproducts_configs

    The name of the new configuration in ZooKeeper will be the same name of the created collection: "collection3"

    Create the collection:
    $ ${SOLR_ROOT}/bin/solr create_collection -c collection3 -d _default

    Output:
    WARNING: Using _default configset with data driven schema functionality.
    NOT RECOMMENDED for production use.
    To turn off: bin/solr config -c collection3 -p 8984 -action set-user-property -property update.autoCreateFields -value false
    Created collection 'collection3' with 1 shard(s), 1 replica(s) with config-set 'collection3'
  6. Create a collection + uploading to ZooKeeper a custom Solr configuration (custom path)
    You can create a collection and specify a path of a Solr configuration directory (using the parameter "-d DIRECTORY_PATH") that will be used to create and upload the Solr configuration to ZooKeeper.

    Solr will try to find the Solr configuration files in the provided directory "DIRECTORY_PATH/".
    If not found, Solr will look at the "conf/" folder under the provided directory "DIRECTORY_PATH/conf/".
    If not found, Solr will look at the "server/solr/configsets/conf/" folder under the provided directory "DIRECTORY_PATH/server/solr/configsets/conf/".

    The name of the new configuration in ZooKeeper will be the same name of the created collection: "collection4"

    Create the collection:
    $ ${SOLR_ROOT}/bin/solr create_collection -c collection4 -d ${SOLR_HOME}/configsets/_default/conf

    Output:
    Created collection 'collection4' with 1 shard(s), 1 replica(s) with config-set 'collection4'
  7. Create a collection + uploading to ZooKeeper the default Solr configuration + overriding the default name of the Solr configuration in ZooKeeper
    Create the collection:
    $ ${SOLR_ROOT}/bin/solr create_collection -c collection5 -d _default -n solr_default_5

    Output:
    Created collection 'collection5' with 1 shard(s), 1 replica(s) with config-set 'solr_default_5'
  8. Create a collection with 2 shards and 2 replicas (copies)
    You need to have 2 Solr instances (up and running)

    Create the collection:
    $ ${SOLR_ROOT}/bin/solr create_collection -c collection6 -n solr_config1 -shards 2 -replicationFactor 2

    Output:
    Re-using existing configuration directory solr_config1
    Created collection 'collection6' with 2 shard(s), 2 replica(s) with config-set 'solr_config1'

    Solr - collections:
    Apache Solr/create_collection

    Notes:

    • A znode "/solr/collections/collection6" (Solr collection) will be creacted in ZooKeeper and will contain the following znodes:
      counter
      leader_elect
      leaders
      state.json
      terms

    • The znode "/solr/configs/solr_config1" (Solr configuration) contain the following znodes:
      managed-schema
      solrconfig.xml
      currency.xml
      elevate.xml
      params.json
      protwords.txt
      stopwords.txt
      synonyms.txt
      ...

    • The shards/replicas of the collection will be created in the file system:
      $ ls -1 ${SOLR_ROOT_INSTANCE_1}/server/solr/
      collection6_shard1_replica_n2
      collection6_shard2_replica_n6

      $ ls -1 ${SOLR_ROOT_INSTANCE_2}/server/solr/
      collection6_shard1_replica_n1
      collection6_shard2_replica_n4

    • See more details in these files:
      ► ${SOLR_ROOT_INSTANCE_1}/server/solr/collection6_shard1_replica_n2/core.properties
      ► ${SOLR_ROOT_INSTANCE_1}/server/solr/collection6_shard2_replica_n6/core.properties

      ► ${SOLR_ROOT_INSTANCE_2}/server/solr/collection6_shard1_replica_n1/core.properties
      ► ${SOLR_ROOT_INSTANCE_2}/server/solr/collection6_shard2_replica_n4/core.properties

      $ cat ${SOLR_ROOT_INSTANCE_1}/server/solr/collection6_shard1_replica_n2/core.properties
      name=collection6_shard1_replica_n2
      collection=collection6
      collection.configName=solr_config1
      numShards=2
      shard=shard1
      coreNodeName=core_node5
      replicaType=NRT
© 2025  mtitek