Elasticsearch叢集API


此API用於獲取有關叢集及其節點的資訊,並對其進行更改。 對於呼叫此API,需要指定節點名稱,地址或_local。 例如,

GET http://localhost:9200/_nodes/_local

或者

Get http://localhost:9200/_nodes/127.0.0.1

響應

... ...
{
   "cluster_name":"elasticsearch", "nodes":{
      "Vy3KxqcHQdm4cIM22U1ewA":{
         "name":"Red Guardian", "transport_address":"127.0.0.1:9300", 
         "host":"127.0.0.1", "ip":"127.0.0.1", "version":"2.1.1", 
         "build":"40e2c53", "http_address":"127.0.0.1:9200",
      }
   }
}
... ...

叢集執行狀況

此API用於通過追加health關鍵字來獲取叢集執行狀況的狀態。 例如,

GET http://localhost:9200/_cluster/health

響應

{
   "cluster_name":"elasticsearch", "status":"yellow", "timed_out":false,
   "number_of_nodes":1, "number_of_data_nodes":1, "active_primary_shards":23,
   "active_shards":23, "relocating_shards":0, "initializing_shards":0,
   "unassigned_shards":23, "delayed_unassigned_shards":0, "number_of_pending_tasks":0,
   "number_of_in_flight_fetch":0, "task_max_waiting_in_queue_millis":0,
   "active_shards_percent_as_number":50.0
}

叢集狀態

此API用於通過附加’state‘關鍵字URL來獲取有關叢集的狀態資訊。狀態資訊包含:版本,主節點,其他節點,路由表,後設資料和塊。 例如,

GET http://localhost:9200/_cluster/state 10. Elasticsearch — Cluster APIs

響應

{
   "cluster_name":"elasticsearch", "version":27, "state_uuid":"B3P7uHGKQUGsSsiX2rGYUQ",
   "master_node":"Vy3KxqcHQdm4cIM22U1ewA",

}

群集統計資訊

此API有助於使用’stats‘關鍵字檢索有關叢集的統計資訊。 此API返回碎片編號,儲存大小,記憶體使用情況,節點數,角色,作業系統和檔案系統。 例如,

GET http://localhost:9200/_cluster/stats

響應

{
   "timestamp":1454496710020, "cluster_name":"elasticsearch", "status":"yellow",
   "indices":{
      "count":5, "shards":{
         "total":23, "primaries":23, "replication":0.0,"
      }
   }
}

正在等待的群集任務

此API用於監視任何叢集中的掛起任務。任務類似於建立索引,更新對映,分配碎片,故障碎片等。例如,

GET http://localhost:9200/_cluster/pending_tasks

叢集重新路由

此API用於將分片從一個節點移動到另一個節點,或者用於取消任何分配或分配任何未分配的碎片。 例如,

POST http://localhost:9200/_cluster/reroute

請求正文

{
   "commands" : [ 
      {
         "move" :
         {
            "index" : "schools", "shard" : 2,
            "from_node" : "nodea", "to_node" : "nodeb"
         }
      },

      {
         "allocate" : {
            "index" : "test", "shard" : 1, "node" : "nodec"
         }
      }
   ]
}

群集更新設定

此API允許使用settings關鍵字更新群集的設定。有兩種型別的設定 - persistent(在重新啟動時應用)和transient(在完全群集重新啟動後不會生存)。

節點統計

此API用於檢索叢集的一個節點的統計資訊。節點狀態與叢集幾乎相同。 例如,

GET http://localhost:9200/_nodes/stats

響應

{
   "cluster_name":"elasticsearch", "nodes":{
      "Vy3KxqcHQdm4cIM22U1ewA":{
         "timestamp":1454497097572, "name":"Red Guardian", 
         "transport_address":"127.0.0.1:9300", "host":"127.0.0.1", "ip":["127.0.0.1:9300",
      }
   }
}

節點hot_threads

此API可用於檢索有關叢集中每個節點上當前熱執行緒的資訊。 例如,

GET http://localhost:9200/_nodes/hot_threads

響應

{Red Guardian} {Vy3KxqcHQdm4cIM22U1ewA} {127.0.0.1}{127.0.0.1:9300}Hot threads at 
   2017-02-01T10:59:48.856Z, interval = 500ms, busiestThreads = 3, 
   ignoreIdleThreads = true:0.0% (0s out of 500ms) cpu usage by thread 'Attach Listener'
      unique snapshot
      unique snapshot