Solr配置:Collections API完整指南

Solr配置:Collections API完整指南

SolrCloud集群包含许多组件。Collections API用于控制集群,包括集合、分片、副本、备份、领导者选举和其他操作需求。

由于此API具有大量命令和选项,我们将命令分组到以下子部分中:

集群节点管理:定义整个集群的属性;检查集群状态;从节点中删除副本;利用新添加的节点;为节点添加或删除角色。

集合管理:创建、列出、重新加载和删除集合;设置集合属性;将文档迁移到另一个集合;重新平衡领导者;备份和恢复集合。

别名管理:创建、列出或删除集合别名;设置别名属性。

分片管理:创建和删除分片;将分片拆分为两个或更多附加分片;强制分片领导者。

副本管理:添加或删除副本;设置副本属性;将副本移动到不同节点。

异步调用

由于一些集合API调用可能是长时间运行的任务(如SPLITSHARD),您可以选择让调用异步运行。指定async=<request-id>可以进行异步调用,可以随时使用REQUESTSTATUS调用请求其状态。提供的ID可以是任何字符串,只要不包含/

截至目前,REQUESTSTATUS不会自动清理跟踪数据结构,这意味着已完成或失败任务的状态会保存在ZooKeeper中,除非手动清除。可以使用DELETESTATUS清除存储的状态。但是,集群中存储的异步调用响应数量限制为10,000个。

异步请求示例

输入

V1 API

1
http://localhost:8983/solr/admin/collections?action=SPLITSHARD&collection=collection1&shard=shard1&async=1000

V2 API

1
2
3
4
5
6
7
8
curl -X POST http://localhost:8983/api/collections/collection1/shards -H 'Content-Type: application/json' -d '
{
"split": {
"shard": "shard1",
"async": "1000"
}
}
'

输出

1
2
3
4
5
{
"responseHeader":{
"status":0,
"QTime":115},
"requestid":"1000"}

REQUESTSTATUS:请求异步调用状态

请求已提交的异步集合API调用的状态和响应。此调用也用于清理存储的状态。

V1 API

1
http://localhost:8983/solr/admin/collections?action=REQUESTSTATUS&requestid=1000

V2 API

1
curl -X GET http://localhost:8983/api/cluster/command-status/1000

REQUESTSTATUS参数

requestid

  • 必需参数,默认值:无
  • 请求的用户定义请求ID
  • 可用于跟踪提交的异步任务的状态

REQUESTSTATUS使用示例

输入:有效请求ID

1
http://localhost:8983/solr/admin/collections?action=REQUESTSTATUS&requestid=1000&wt=xml

输出

1
2
3
4
5
6
7
8
9
10
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">1</int>
</lst>
<lst name="status">
<str name="state">completed</str>
<str name="msg">found 1000 in completed tasks</str>
</lst>
</response>

输入:无效请求ID

1
http://localhost:8983/solr/admin/collections?action=REQUESTSTATUS&requestid=1004&wt=xml

输出

1
2
3
4
5
6
7
8
9
10
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">1</int>
</lst>
<lst name="status">
<str name="state">notfound</str>
<str name="msg">Did not find taskid [1004] in any tasks queue</str>
</lst>
</response>

DELETESTATUS:删除状态

删除已失败或完成的异步集合API调用的存储响应。

V1 API

1
http://localhost:8983/solr/admin/collections?action=DELETESTATUS&requestid=1000

V2 API

删除单个请求响应:

1
curl -X DELETE http://localhost:8983/api/cluster/command-status/1000

清除所有存储的已完成和失败的异步请求响应:

1
curl -X DELETE http://localhost:8983/api/cluster/command-status?flush=true

DELETESTATUS参数

requestid

  • 可选参数,默认值:无
  • 要清除其存储响应的异步调用的请求ID

flush

  • 可选参数,默认值:无
  • 设置为true可清除所有存储的已完成和失败的异步请求响应

DELETESTATUS使用示例

输入:有效请求ID

1
http://localhost:8983/solr/admin/collections?action=DELETESTATUS&requestid=foo&wt=xml

输出

1
2
3
4
5
6
7
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">1</int>
</lst>
<str name="status">successfully removed stored response for [foo]</str>
</response>

输入:无效请求ID

1
http://localhost:8983/solr/admin/collections?action=DELETESTATUS&requestid=bar&wt=xml

输出

1
2
3
4
5
6
7
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">1</int>
</lst>
<str name="status">[bar] not found in stored responses</str>
</response>

输入:清除所有存储状态

1
http://localhost:8983/solr/admin/collections?action=DELETESTATUS&flush=true&wt=xml

输出

1
2
3
4
5
6
7
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">1</int>
</lst>
<str name="status"> successfully cleared stored collection api responses </str>
</response>

总结

Collections API是SolrCloud集群管理的核心工具,提供了全面的集合、分片和副本管理功能。通过异步调用机制,可以有效处理长时间运行的操作,而状态管理功能确保了操作的可追踪性和可控性。合理使用这些API可以大大简化SolrCloud集群的维护和管理工作。

© 2025 Solr Community of China All Rights Reserved. 本站访客数人次 本站总访问量
Theme by hiero