国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Elasticsearch 常用 REST API 之集群APIs

這篇具有很好參考價值的文章主要介紹了Elasticsearch 常用 REST API 之集群APIs。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

Cluster health API

集群運行狀況API返回關于集群運行狀況的簡單狀態(tài)。您還可以使用API僅獲取指定數(shù)據(jù)流和索引的健康狀態(tài)。對于數(shù)據(jù)流,API 檢索流的支持索引的運行狀況。

集群健康狀態(tài)為:綠色、黃色和紅色。在shard級別,紅色狀態(tài)表示集群中沒有分配特定的shard,黃色狀態(tài)表示主shard已分配,但副本未分配,綠色狀態(tài)表示所有shard都已分配。索引級別狀態(tài)由最差分片狀態(tài)控制。集群狀態(tài)由最差索引狀態(tài)控制。

GET /_cluster/health/<target>

<target>: (可選,string)以逗號分隔的數(shù)據(jù)流、索引和索引別名列表,用于限制請求。支持通配符表達式()。如果要針對集群中的所有數(shù)據(jù)流和索引,可以省略該參數(shù)或使用_all或。

  • 查詢參數(shù) (舉例)
    level : (可選,字符串)可以是cluster、indices或 之一shards??刂品祷氐慕】敌畔⒌脑敿毤墑e。默認為cluster。
    timeout: (可選,時間單位)等待響應的時間。如果超時之前未收到響應,則請求失敗并返回錯誤。默認為30s。
    wait_for_status:(可選,字符串)綠色、黃色或紅色中的一種。將等待(直到提供的超時),直到集群狀態(tài)變?yōu)樘峁┑臓顟B(tài)或更好,即綠色>黃色>紅色。缺省情況下,不等待任何狀態(tài)。

該API的主要優(yōu)點之一是能夠等待,直到集群達到某個較高的健康水平。例如,下面的代碼將等待60秒使集群達到綠色狀態(tài)(如果在60秒之前達到綠色狀態(tài),它將在該點返回):

# 當前狀態(tài)為黃色
root@ubuntu-x64_02:/opt# curl -X GET "http://192.168.88.12:9201/_cluster/health?pretty" 
{
  "cluster_name" : "my-cluster",
  "status" : "yellow",                  # <----- 狀態(tài)為 yellow 
  "timed_out" : false,
  "number_of_nodes" : 2,
  "number_of_data_nodes" : 2,
  "active_primary_shards" : 19,
  "active_shards" : 38,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 3,
  "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" : 92.6829268292683
}

# 默認 level 為cluster, 上面查詢等同于
root@ubuntu-x64_02:/opt# curl -X GET "http://192.168.88.12:9201/_cluster/health/?level=cluster&pretty" 

# 等待60秒后返回
root@ubuntu-x64_02:/opt# time curl -X GET "http://192.168.88.12:9201/_cluster/health?wait_for_status=green&timeout=60s&pretty" 
{
  "cluster_name" : "my-cluster",
  "status" : "yellow",
  "timed_out" : true,
  "number_of_nodes" : 2,
  "number_of_data_nodes" : 2,
  "active_primary_shards" : 19,
  "active_shards" : 38,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 3,
  "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" : 92.6829268292683
}

real    1m0.014s
user    0m0.000s
sys     0m0.012s

# 如果在60秒之前達到綠色狀態(tài),它將在該點返回(如:30.120s ) 
root@ubuntu-x64_02:/opt# time curl -X GET "http://192.168.88.12:9201/_cluster/health?wait_for_status=green&timeout=60s&pretty" 
{
  "cluster_name" : "my-cluster",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 3,
  "number_of_data_nodes" : 3,
  "active_primary_shards" : 19,
  "active_shards" : 41,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 1,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}

real    0m30.120s
user    0m0.000s
sys     0m0.004s

以下是獲取 shards 級別 集群健康狀況的示例 :

root@ubuntu-x64_02:/opt# curl -X GET "http://192.168.88.12:9201/_cluster/health/_all?level=shards&pretty" 
{
  "cluster_name" : "my-cluster",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 3,
  "number_of_data_nodes" : 3,
  "active_primary_shards" : 19,
  "active_shards" : 41,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "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" : 100.0,
  "indices" : {
    ".ds-ilm-history-5-2023.05.04-000004" : {
      "status" : "green",
      "number_of_shards" : 1,
      "number_of_replicas" : 1,
      "active_primary_shards" : 1,
      "active_shards" : 2,
      "relocating_shards" : 0,
      "initializing_shards" : 0,
      "unassigned_shards" : 0,
      "shards" : {
        "0" : {
          "status" : "green",
          "primary_active" : true,
          "active_shards" : 2,
          "relocating_shards" : 0,
          "initializing_shards" : 0,
          "unassigned_shards" : 0
        }
      }
    },
    ..........

Cluster state API

返回有關集群狀態(tài)的元數(shù)據(jù)。

GET /_cluster/state/<metrics>/<target>
  • 如果啟用了Elasticsearch安全功能,您必須具有monitor或 manage 集群權(quán)限才能使用此API。
  • 集群狀態(tài) API 允許訪問代表整個集群狀態(tài)的元數(shù)據(jù)。這包括以下信息:
    • 集群中的節(jié)點集
    • 所有集群級別設置
    • 有關集群中索引的信息,包括它們的映射和設置
    • 集群中所有分片的位置。

路徑參數(shù)

集群狀態(tài)包含關于集群中所有索引的信息,包括它們的映射,以及模板和其他元數(shù)據(jù)。這意味著它有時會非常大。為了避免需要處理所有這些信息,你可以只請求你需要的部分集群狀態(tài):

<metrics>: (可選,字符串)以下選項的逗號分隔列表:

  • _all: 顯示所有指標。
  • blocks:顯示blocks響應的部分。
  • metadata: 顯示metadata響應的部分。如果您提供逗號分隔的索引列表,則返回的輸出將僅包含這些索引的元數(shù)據(jù)。
  • routing_table:顯示routing_table響應的部分。如果您提供逗號分隔的索引列表,則返回的輸出將僅包含這些索引的路由表。

<target>:(可選,string)以逗號分隔的數(shù)據(jù)流、索引和別名列表,用于限制請求。支持通配符()。要針對所有數(shù)據(jù)流和索引,省略該參數(shù)或使用或_all。

下面的例子只返回 my-index-000001 的數(shù)據(jù)流或索引的 metadata 和 routing_table 數(shù)據(jù):

root@ubuntu-x64_02:/opt# curl -X GET "http://192.168.88.12:9201/_cluster/state/metadata,routing_table/my-index-000001?pretty"
{
  "cluster_name" : "my-cluster",
  "cluster_uuid" : "hhRd0sm5SXqDi3oceLw3oQ",
  "metadata" : {
    ......
    "cluster_coordination" : {
     ......
    },
    "templates" : { },
    "indices" : {
      "my-index-000001" : {
        "version" : 17,
        ......
        "routing_num_shards" : 1024,
        "state" : "open",
        "settings" : {
          "index" : {
            ......
          }
        },
        "mappings" : {
          "_doc" : {
            "properties" : {
              "employee-id" : {
                "index" : false,
                "type" : "keyword"
              },
             ......
            }
          }
        },
       ......
      }
    },
    "index-graveyard" : {
      "tombstones" : [ ]
    }
  },
  "routing_table" : {
    "indices" : {
      "my-index-000001" : {
        "shards" : {
          "0" : [
            {
              "state" : "STARTED",
              "primary" : true,
              "node" : "vPD3eY-FSP6PcX1xY3SEyg",
              "relocating_node" : null,
              "shard" : 0,
              "index" : "my-index-000001",
              "allocation_id" : {
                "id" : "qOrfDS_aQCqf4pxR8xP3pA"
              }
            },
            {
              "state" : "STARTED",
              "primary" : false,
              "node" : "QPS7tRDBRnCbpv0Dfx_0Lg",
              "relocating_node" : null,
              "shard" : 0,
              "index" : "my-index-000001",
              "allocation_id" : {
                "id" : "lEzlrVv7SNKvqZasj_hRcA"
              }
            }
          ]
        }
      }
    }
  }
}

此示例僅返回 blocks 元數(shù)據(jù):

root@ubuntu-x64_02:/opt# curl -X GET "http://192.168.88.12:9201/_cluster/state/blocks/my-index-000001?pretty"
{
  "cluster_name" : "my-cluster",
  "cluster_uuid" : "hhRd0sm5SXqDi3oceLw3oQ",
  "blocks" : { }
}

Cluster allocation explain API

提供對分片當前分配的解釋。

GET _cluster/allocation/explain

POST _cluster/allocation/explain
  • 如果啟用了Elasticsearch安全功能,您必須具有monitor或 manage 集群權(quán)限才能使用此API。

集群分配解釋API的目的是為集群中的分片分配提供解釋。

  • 對于未分配的分片,explain API提供了對分片未分配原因的解釋。
  • 對于已分配的分片,explain API提供了一個解釋,說明為什么分片保留在當前節(jié)點上,而沒有移動或重新平衡到另一個節(jié)點。

當試圖診斷為什么碎片未分配或為什么碎片繼續(xù)保留在當前節(jié)點上時,這個API非常有用。

未分配的主分片, 下面的請求獲取未分配主分片的分配解釋。

# 創(chuàng)建索引 my-index-000002, 并讓其分配到  "name" : "nonexistent_node" 的節(jié)點上
root@ubuntu-x64_02:/opt# curl -X PUT "http://192.168.88.12:9201/my-index-000002/?pretty"  -H 'Content-Type: application/json' -d'
> {
>     "settings" : {
>       "index" : {
>         "routing" : {
>           "allocation" : {
>             "include" : {
>               "name" : "nonexistent_node"
>             }
>           }
>         },
>         "number_of_shards" : "1",
>         "number_of_replicas" : "1"
>       }
>     }
> }
> '

{
  "acknowledged" : true,
  "shards_acknowledged" : false,
  "index" : "my-index-000002"
}

查看解釋索引 my-index-000002 未分配主分片的原因: 無法分配,因為任何節(jié)點都不允許分配

root@ubuntu-x64_02:/opt# curl -X GET "http://192.168.88.12:9201/_cluster/allocation/explain?pretty" -H 'Content-Type: application/json' -d'
> {
>   "index": "my-index-000002",
>   "shard": 0,
>   "primary": true
> }
> '
{
  "index" : "my-index-000002",
  "shard" : 0,
  "primary" : true,
  "current_state" : "unassigned",   # <------  分片的當前狀態(tài)。 
  "unassigned_info" : {
    "reason" : "INDEX_CREATED",     # <------------ 分片最初變得未分配的原因。
    "at" : "2023-12-26T05:54:44.326Z",
    "last_allocation_status" : "no"
  },
  "can_allocate" : "no",    # <---------------- 是否分配分片
  "allocate_explanation" : "cannot allocate because allocation is not permitted to any of the nodes",
  "node_allocation_decisions" : [
    {
      "node_id" : "QPS7tRDBRnCbpv0Dfx_0Lg",
      "node_name" : "node-3",
      "transport_address" : "192.168.88.12:9303",
      "node_attributes" : {
        "ml.machine_memory" : "6248390656",
        "ml.max_open_jobs" : "512",
        "xpack.installed" : "true",
        "ml.max_jvm_size" : "1073741824",
        "transform.node" : "true"
      },
      "node_decision" : "no",    # <------------ 是否將分片分配給特定節(jié)點。 
      "weight_ranking" : 1,
      "deciders" : [
        {
          "decider" : "filter",    # <------------   導致no節(jié)點決策的決策者。 
          "decision" : "NO",
          # 解釋決策者返回決策的原因no,并提供有用的提示,指出導致決策的設置。
          "explanation" : "node does not match index setting [index.routing.allocation.include] filters [name:\"nonexistent_node\"]"    
        }
      ]
    },
    {
      "node_id" : "vPD3eY-FSP6PcX1xY3SEyg",
      "node_name" : "node-1",
      "transport_address" : "192.168.88.12:9301",
      "node_attributes" : {
        "ml.machine_memory" : "6248390656",
        "ml.max_open_jobs" : "512",
        "xpack.installed" : "true",
        "ml.max_jvm_size" : "1073741824",
        "transform.node" : "true"
      },
      "node_decision" : "no",
      "weight_ranking" : 2,
      "deciders" : [
        {
          "decider" : "filter",
          "decision" : "NO",
          "explanation" : "node does not match index setting [index.routing.allocation.include] filters [name:\"nonexistent_node\"]"
        }
      ]
    },
    {
      "node_id" : "32zPm9fvTPGxPMvNSsCZrw",
      "node_name" : "node-2",
      "transport_address" : "192.168.88.12:9302",
      "node_attributes" : {
        "ml.machine_memory" : "6248390656",
        "ml.max_open_jobs" : "512",
        "xpack.installed" : "true",
        "ml.max_jvm_size" : "1073741824",
        "transform.node" : "true"
      },
      "node_decision" : "no",
      "weight_ranking" : 3,
      "deciders" : [
        {
          "decider" : "filter",
          "decision" : "NO",
          "explanation" : "node does not match index setting [index.routing.allocation.include] filters [name:\"nonexistent_node\"]"
        }
      ]
    }
  ]
}

修改 name 為 節(jié)點的 已存在的,則 主分片 可以分配成功:

root@ubuntu-x64_02:/opt# curl -X PUT "http://192.168.88.12:9201/my-index-000002/_settings"  -H 'Content-Type: application/json' -d'
> {
>   "index" : {
>         "routing" : {
>             "allocation" : {
>                 "include" : {
>                     "name" : "node-1"
>                 }
>             }
>         }
>     }
> }
> '
{"acknowledged":true}

# 此時狀態(tài)為 yellow , 黃色狀態(tài)表示主shard已分配,但副本未分配
root@ubuntu-x64_02:/opt# curl -X GET "http://192.168.88.12:9201/_cluster/health/my-index-000002?level=shards&pretty" 
{
  "cluster_name" : "my-cluster",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 3,
  "number_of_data_nodes" : 3,
  "active_primary_shards" : 1,
  "active_shards" : 1,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 1,    
  "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" : 97.67441860465115,
  "indices" : {
    "my-index-000002" : {
      "status" : "yellow",
      "number_of_shards" : 1,
      "number_of_replicas" : 1,
      "active_primary_shards" : 1,
      "active_shards" : 1,
      "relocating_shards" : 0,
      "initializing_shards" : 0,
      "unassigned_shards" : 1,
      "shards" : {
        "0" : {
          "status" : "yellow",
          "primary_active" : true,
          "active_shards" : 1,
          "relocating_shards" : 0,
          "initializing_shards" : 0,
          "unassigned_shards" : 1
        }
      }
    }
  }
}

此時,集群狀態(tài)為黃色, 集群狀態(tài)由最差索引狀態(tài)控制。文章來源地址http://www.zghlxwxcb.cn/news/detail-781738.html

root@ubuntu-x64_02:/opt# curl -X GET "http://192.168.88.12:9201/_cluster/health?pretty" 
{
  "cluster_name" : "my-cluster",
  "status" : "yellow",    # <-----------  集群狀態(tài)由最差索引狀態(tài)控制 
  "timed_out" : false,
  "number_of_nodes" : 3,
  "number_of_data_nodes" : 3,
  "active_primary_shards" : 20,
  "active_shards" : 42,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 1,
  "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" : 97.67441860465115
}

到了這里,關于Elasticsearch 常用 REST API 之集群APIs的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • Elasticsearch:從 Java High Level Rest Client 切換到新的 Java API Client

    Elasticsearch:從 Java High Level Rest Client 切換到新的 Java API Client

    作者:David Pilato 我經(jīng)常在討論中看到與 Java API 客戶端使用相關的問題。 為此,我在 2019 年啟動了一個 GitHub 存儲庫,以提供一些實際有效的代碼示例并回答社區(qū)提出的問題。 從那時起,高級 Rest 客戶端 (High Level Rest Cliet - HLRC) 已被棄用,并且新的 Java API 客戶端已發(fā)布。 為了

    2024年03月19日
    瀏覽(36)
  • ES基礎篇 常用API之集群類API

    ES基礎篇 常用API之集群類API

    Elasticsearch作為非關系型數(shù)據(jù)庫,在某種程度上和關系型數(shù)據(jù)庫相似,作為數(shù)據(jù)庫,我們的主要作用就是存儲數(shù)據(jù)、檢索數(shù)據(jù);在關系型數(shù)據(jù)庫中,我們可以使用SQL語句和數(shù)據(jù)庫進行交互,而Elasticsearch則為我們提供了豐富的Rest風格的API,通過客戶端操作ES本質(zhì)上依然是Restful

    2024年01月19日
    瀏覽(13)
  • 【ElasticSearch】ElasticSearch常用查詢api集合(一)

    【ElasticSearch】ElasticSearch常用查詢api集合(一)

    本文為es常見DSL搜索入門帖子 開始之前先貼個對應關系,方便各位理解 在es7+的版本中,是沒有類型的概念的,所以,添加數(shù)據(jù)直接在索引中添加; ?請求es地址均為 localhost:9200/{索引}/_search ,為了編寫方便些,在下面的例子中會直接寫請求體; bool : 用來組合多個條件

    2024年02月11日
    瀏覽(52)
  • ElasticSearch 基礎之 常用 API 測試

    ElasticSearch 基礎之 常用 API 測試

    本文詳細介紹了ElasticSearch 8.6.2版本的常用API測試,包括查看(Cat)API和集群(Cluster)API的使用,以及如何通過Kibana進行測試。文章還提供了詳細的命令示例和返回結(jié)果解析。

    2024年02月06日
    瀏覽(10)
  • ASP.NET Core 中基于 Minimal APIs 的Web API

    Minimal APIs 是ASP.NET Core中快速構(gòu)建 REST API 的方式,可以用最少的代碼構(gòu)建全功能的REST API。比如下面三行代碼: 可以實現(xiàn)在請求網(wǎng)站根目錄結(jié)點的時候,返回\\\"Hello World!\\\"。 這種方式的Web API可以用于構(gòu)建微服務,極簡功能的網(wǎng)站。 下面代碼,將幾個 HTTP 請求的 url映射到 Lambda

    2024年02月10日
    瀏覽(25)
  • Elasticsearch的 8.x常用api匯總

    Elasticsearch的 8.x常用api匯總

    首先, 安裝?Kibana! 下載Elasticsearch,官方下載頁面; Elasticsearch 參考,官方文檔;

    2024年02月03日
    瀏覽(14)
  • 【ElasticSearch】docker部署ElasticSearch、常用Restful API的使用(一)

    【ElasticSearch】docker部署ElasticSearch、常用Restful API的使用(一)

    Elaticsearch ,簡稱為es,es是一個開源的 高擴展 的 分布式全文檢索引擎 ,它可以近乎 實時的存儲 、 檢索數(shù)據(jù); 本身擴展性很好,可以擴展到上百臺服務器,處理PB級別(大數(shù)據(jù)時代)的數(shù)據(jù)。es也使用java開發(fā)并使用Lucene作為其核心來實現(xiàn)所有索引和搜索的功能,但是它的 目的

    2024年01月20日
    瀏覽(13)
  • 【ElasticSearch】ElasticSearch Java API的使用——常用索引、文檔、查詢操作(二)

    Elaticsearch ,簡稱為es,es是一個開源的 高擴展 的 分布式全文檢索引擎 ,它可以近乎 實時的存儲 、 檢索數(shù)據(jù); 本身擴展性很好,可以擴展到上百臺服務器,處理PB級別(大數(shù)據(jù)時代)的數(shù)據(jù)。es也使用java開發(fā)并使用Lucene作為其核心來實現(xiàn)所有索引和搜索的功能,但是它的 目的

    2024年01月16日
    瀏覽(124)
  • Elasticsearch8.x版本Java客戶端Elasticsearch Java API Client中常用API練習

    在Es7.15版本之后,es官方將它的高級客戶端RestHighLevelClient標記為棄用狀態(tài)。同時推出了全新的java API客戶端Elasticsearch Java API Client,該客戶端也將在Elasticsearch8.0及以后版本中成為官方推薦使用的客戶端。 Elasticsearch Java API Client支持除Vector title search API和Find structure API之外的所有

    2024年04月11日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包