Apache Solr - Core
Solr Core 是 Lucene 索引的运行实例,包含使用它所需的所有 Solr 配置文件。我们需要创建一个 Solr Core 来执行索引和分析等操作。
Solr 应用程序可能包含一个或多个核心。如有必要,Solr 应用程序中的两个核心可以相互通信。
创建核心
安装并启动 Solr 后,您可以连接到 Solr 的客户端(Web 界面)。

如以下屏幕截图所示,Apache Solr 中最初没有核心。现在,我们将了解如何在 Solr 中创建核心。
使用 create 命令
创建核心的一种方法是使用 create 命令创建 无模式核心,如下所示 −
[Hadoop@localhost bin]$ ./Solr create -c Solr_sample
在这里,我们尝试在 Apache Solr 中创建一个名为 Solr_sample 的核心。此命令创建一个显示以下消息的核心。
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" }
您可以在 Solr 中创建多个核心。在 Solr Admin 的左侧,您可以看到一个 核心选择器,您可以在其中选择新创建的核心,如以下屏幕截图所示。

使用 create_core 命令
或者,您可以使用 create_core 命令创建核心。此命令具有以下选项 −
–c core_name | 要创建的核心的名称 |
-p port_name | 要在其中创建核心的端口 |
-d conf_dir | 端口的配置目录 |
让我们看看如何使用 create_core 命令。在这里,我们将尝试创建一个名为 my_core 的核心。
[Hadoop@localhost bin]$ ./Solr create_core -c my_core
执行时,上述命令会创建一个核心,并显示以下消息 −
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" }
删除核心
您可以使用 Apache Solr 的 delete 命令删除核心。假设我们在 Solr 中有一个名为 my_core 的核心,如以下屏幕截图所示。

您可以使用 delete 命令删除此核心,方法是将核心的名称传递给此命令,如下所示 −
[Hadoop@localhost bin]$ ./Solr delete -c my_core
执行上述命令后,将删除指定的核心,并显示以下消息。
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 } }
您可以打开 Solr 的 Web 界面来验证核心是否已被删除。
