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

上一篇: Elasticsearch索引API 下一篇: Elasticsearch入門教學