集合 API

SolrCloud 叢集包含許多元件。提供集合 API 讓您控制叢集,包括集合、分片、副本、備份、領導者選舉和其他需要的操作。

由於此 API 有大量的命令和選項,我們將命令分組到以下子章節中

叢集和節點管理命令:定義整個叢集的屬性;檢查叢集的狀態;從節點移除副本;利用新加入的節點;為節點新增或移除角色。

集合管理命令:建立、列出、重新載入和刪除集合;設定集合屬性;將文件遷移到另一個集合;重新平衡領導者;備份和還原集合。

別名管理:建立、列出或刪除集合別名;設定別名屬性。

分片管理命令:建立和刪除分片;將分片分割成兩個或多個額外的分片;強制分片領導者。

副本管理命令:新增或刪除副本;設定副本屬性;將副本移動到不同的節點。

非同步呼叫

由於某些集合 API 呼叫可能是長時間執行的任務(例如 SPLITSHARD),您可以選擇讓呼叫非同步執行。指定 async=<request-id> 可讓您進行非同步呼叫,其狀態可隨時使用 REQUESTSTATUS 呼叫要求。提供的 ID 可以是任何字串,只要其中沒有 /

目前,REQUESTSTATUS 不會自動清除追蹤資料結構,這表示除非手動清除,否則已完成或失敗任務的狀態會保留在 ZooKeeper 中。可以使用 DELETESTATUS 來清除儲存的狀態。但是,叢集中儲存的非同步呼叫回應數量上限為 10,000 個。

非同步請求範例

輸入

  • V1 API

  • V2 API

https://127.0.0.1:8983/solr/admin/collections?action=SPLITSHARD&collection=collection1&shard=shard1&async=1000
curl -X POST https://127.0.0.1:8983/api/collections/collection1/shards -H 'Content-Type: application/json' -d '
  {
    "split": {
      "shard": "shard1",
      "async": "1000"
    }
  }
'

輸出

{
  "responseHeader":{
    "status":0,
    "QTime":115},
  "requestid":"1000"}

REQUESTSTATUS:非同步呼叫的要求狀態

請求已提交的非同步集合 API(如下)呼叫的狀態和回應。此呼叫也用於清除儲存的狀態。

  • V1 API

  • V2 API

https://127.0.0.1:8983/solr/admin/collections?action=REQUESTSTATUS&requestid=1000
curl -X GET https://127.0.0.1:8983/api/cluster/command-status/1000

REQUESTSTATUS 參數

requestid

必要

預設值:無

使用者定義的要求 ID。這可以用於追蹤提交的非同步任務的狀態。

使用 REQUESTSTATUS 的範例

輸入:有效的要求 ID

https://127.0.0.1:8983/solr/admin/collections?action=REQUESTSTATUS&requestid=1000&wt=xml

輸出

<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

https://127.0.0.1:8983/solr/admin/collections?action=REQUESTSTATUS&requestid=1004&wt=xml

輸出

<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

  • V2 API

https://127.0.0.1:8983/solr/admin/collections?action=DELETESTATUS&requestid=1000

刪除單一請求回應

curl -X DELETE https://127.0.0.1:8983/api/cluster/command-status/1000

清除所有已儲存的完成和失敗的非同步請求回應

curl -X DELETE https://127.0.0.1:8983/api/cluster/command-status?flush=true

DELETESTATUS 參數

requestid

可選

預設值:無

應清除其儲存回應的非同步呼叫的請求 ID。

flush(清除)

可選

預設值:無

設定為 true 以清除所有已儲存的完成和失敗的非同步請求回應。

使用 DELETESTATUS 的範例

輸入:有效的要求 ID

https://127.0.0.1:8983/solr/admin/collections?action=DELETESTATUS&requestid=foo&wt=xml

輸出

<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

https://127.0.0.1:8983/solr/admin/collections?action=DELETESTATUS&requestid=bar&wt=xml

輸出

<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>

輸入:清除所有已儲存的狀態

https://127.0.0.1:8983/solr/admin/collections?action=DELETESTATUS&flush=true&wt=xml

輸出

<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>