Apache Solr – Core

A Solr Core is a running instance of a Lucene index that contains all the Solr configuration files required to use it. We need to create a Solr Core to perform operations like indexing and analyzing.

A Solr application may contain one or multiple cores. If necessary, two cores in a Solr application can communicate with each other.

Creating a Core

After installing and starting Solr, you can connect to the client (web interface) of Solr.

create core

As highlighted in the following screenshot, initially there are no cores in Apache Solr. Now, we will see how to create a core in Solr.

Using create command

One way to create a core is to create a schema-less core using the create command, as shown below āˆ’

[Hadoop@localhost bin]$ ./Solr create -c Solr_sample 

Here, we are trying to create a core named Solr_sample in Apache Solr. This command creates a core displaying the following message.

Copying configuration to new core instance directory:
/home/Hadoop/Solr/server/Solr/Solr_sample 

Creating new core 'Solr_sample' using command: 
http://localhost:8983/Solr/admin/cores?action=CREATE&name=Solr_sample&instanceD 
ir = Solr_sample {  
   "responseHeader":{    
      "status":0,    
      "QTime":11550
   },  
   "core":"Solr_sample" 
} 

You can create multiple cores in Solr. On the left-hand side of the Solr Admin, you can see a core selector where you can select the newly created core, as shown in the following screenshot.

create core

Using create_core command

Alternatively, you can create a core using the create_core command. This command has the following options āˆ’

ā€“c core_nameName of the core you wanted to create
-p port_namePort at which you want to create the core
-d conf_dirConfiguration directory of the port

Letā€™s see how you can use the create_core command. Here, we will try to create a core named my_core.

[Hadoop@localhost bin]$ ./Solr create_core -c my_core 

On executing, the above command creates a core displaying the following message āˆ’

Copying configuration to new core instance directory: 
/home/Hadoop/Solr/server/Solr/my_core  

Creating new core 'my_core' using command: 
http://localhost:8983/Solr/admin/cores?action=CREATE&name=my_core&instanceD
ir = my_core {  
   "responseHeader":{  
      "status":0,  
      "QTime":1346
   },  
   "core":"my_core" 
}

Deleting a Core

You can delete a core using theĀ deleteĀ command of Apache Solr. Letā€™s suppose we have a core namedĀ my_coreĀ in Solr, as shown in the following screenshot.

delete core

You can delete this core using the delete command by passing the name of the core to this command as follows āˆ’

[Hadoop@localhost bin]$ ./Solr delete -c my_core 

On executing the above command, the specified core will be deleted displaying the following message.

Deleting core 'my_core' using command: 
http://localhost:8983/Solr/admin/cores?action=UNLOAD&core = my_core&deleteIndex
   = true&deleteDataDir = true&deleteInstanceDir = true  {
   
   "responseHeader" :{    
      "status":0,    
      "QTime":170
   }
} 

You can open the web interface of Solr to verify whether the core has been deleted or not.

Leave a Reply