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