Elasticsearch 常用 REST API 之集群APIs

Cluster health API

集群运行状况API返回关于集群运行状况的简单状态。您还可以使用API仅获取指定数据流和索引的健康状态。对于数据流,API 检索流的支持索引的运行状况。

集群健康状态为:绿色、黄色和红色。在shard级别,红色状态表示集群中没有分配特定的shard,黄色状态表示主shard已分配,但副本未分配,绿色状态表示所有shard都已分配。索引级别状态由最差分片状态控制。集群状态由最差索引状态控制。

GET /_cluster/health/<target>

<target>: (可选,string)以逗号分隔的数据流、索引和索引别名列表,用于限制请求。支持通配符表达式()。如果要针对集群中的所有数据流和索引,可以省略该参数或使用_all或

  • 查询参数 (举例)
    level : (可选,字符串)可以是cluster、indices或 之一shards。控制返回的健康信息的详细级别。默认为cluster。
    timeout: (可选,时间单位)等待响应的时间。如果超时之前未收到响应,则请求失败并返回错误。默认为30s。
    wait_for_status:(可选,字符串)绿色、黄色或红色中的一种。将等待(直到提供的超时),直到集群状态变为提供的状态或更好,即绿色>黄色>红色。缺省情况下,不等待任何状态。

该API的主要优点之一是能够等待,直到集群达到某个较高的健康水平。例如,下面的代码将等待60秒使集群达到绿色状态(如果在60秒之前达到绿色状态,它将在该点返回):

# 当前状态为黄色
root@ubuntu-x64_02:/opt# curl -X GET "http://192.168.88.12:9201/_cluster/health?pretty" 
{"cluster_name" : "my-cluster","status" : "yellow",                  # <----- 状态为 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秒之前达到绿色状态,它将在该点返回(如: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

返回有关集群状态的元数据。

GET /_cluster/state/<metrics>/<target>
  • 如果启用了Elasticsearch安全功能,您必须具有monitor或 manage 集群权限才能使用此API。
  • 集群状态 API 允许访问代表整个集群状态的元数据。这包括以下信息:
    • 集群中的节点集
    • 所有集群级别设置
    • 有关集群中索引的信息,包括它们的映射和设置
    • 集群中所有分片的位置。

路径参数

集群状态包含关于集群中所有索引的信息,包括它们的映射,以及模板和其他元数据。这意味着它有时会非常大。为了避免需要处理所有这些信息,你可以只请求你需要的部分集群状态:

<metrics>: (可选,字符串)以下选项的逗号分隔列表:

  • _all: 显示所有指标。
  • blocks:显示blocks响应的部分。
  • metadata: 显示metadata响应的部分。如果您提供逗号分隔的索引列表,则返回的输出将仅包含这些索引的元数据。
  • routing_table:显示routing_table响应的部分。如果您提供逗号分隔的索引列表,则返回的输出将仅包含这些索引的路由表。

<target>:(可选,string)以逗号分隔的数据流、索引和别名列表,用于限制请求。支持通配符()。要针对所有数据流和索引,省略该参数或使用或_all。

下面的例子只返回 my-index-000001 的数据流或索引的 metadata 和 routing_table 数据:

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 元数据:

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/explainPOST _cluster/allocation/explain
  • 如果启用了Elasticsearch安全功能,您必须具有monitor或 manage 集群权限才能使用此API。

集群分配解释API的目的是为集群中的分片分配提供解释。

  • 对于未分配的分片,explain API提供了对分片未分配原因的解释。
  • 对于已分配的分片,explain API提供了一个解释,说明为什么分片保留在当前节点上,而没有移动或重新平衡到另一个节点。

当试图诊断为什么碎片未分配或为什么碎片继续保留在当前节点上时,这个API非常有用。

未分配的主分片, 下面的请求获取未分配主分片的分配解释。

# 创建索引 my-index-000002, 并让其分配到  "name" : "nonexistent_node" 的节点上
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 未分配主分片的原因: 无法分配,因为任何节点都不允许分配

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",   # <------  分片的当前状态。 "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",    # <------------ 是否将分片分配给特定节点。 "weight_ranking" : 1,"deciders" : [{"decider" : "filter",    # <------------   导致no节点决策的决策者。 "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 为 节点的 已存在的,则 主分片 可以分配成功:

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}# 此时状态为 yellow , 黄色状态表示主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}}}}
}

此时,集群状态为黄色, 集群状态由最差索引状态控制。

root@ubuntu-x64_02:/opt# curl -X GET "http://192.168.88.12:9201/_cluster/health?pretty" 
{"cluster_name" : "my-cluster","status" : "yellow",    # <-----------  集群状态由最差索引状态控制 "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
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/582087.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

高并发下数据库插入操作死锁问题

1. 问题&#xff1a; 项目中出现如下报错&#xff1a; org.springframework.dao.DeadlockLoserDataAccessException: com.xxxMapper.insert (batch index #1) failed. Cause: java.sql.BatchUpdateException: Deadlock found when trying to get lock; try restarting trans…

Transformer实现的一个Demo

RT&#xff0c;直接上代码&#xff0c;可以跑通&#xff1a; #encoding:utf-8 import torch import torch.nn as nn import numpy as np import math class Config(object): def __init__(self): self.vocab_size 6 self.d_model 512 self.n_heads 4 assert self.d_model…

UI自动化Selenium 元素定位之Xpath

一、元素定位方式 selenium中定位元素&#xff0c;通常有几种方式&#xff1a; 1、通过id定位&#xff1a;By.ID 2、通过Name定位&#xff1a;By.Name 3、通过元素其他属性定位&#xff0c;如class、type、text文本。。。。。。等等&#xff0c;如果要用属性定位那就需要使…

图论 经典例题

1 拓扑排序 对有向图的节点排序&#xff0c;使得对于每一条有向边 U-->V U都出现在V之前 *有环无法拓扑排序 indegree[], nxs[];//前者表示节点 i 的入度&#xff0c;后者表示节点 i 指向的节点 queue [] for i in range(n):if indege[i] 0: queue.add(i)// 入度为0的节…

虚析构和纯虚析构

多态使用时&#xff0c;如果子类中有属性开辟到堆区&#xff0c;那么父类的指针在释放时无法调用到子类的析构代码 解决方式&#xff1a;将父类中的析构代码函数改为虚析构或者纯虚析构 虚析构和纯虚析构共性&#xff1a; 可以解决父类指针释放子类对象 都需要有具体的函数…

[SWPUCTF 2021 新生赛]finalrce

[SWPUCTF 2021 新生赛]finalrce wp 注&#xff1a;本文参考了 NSSCTF Leaderchen 师傅的题解&#xff0c;并修补了其中些许不足。 此外&#xff0c;参考了 命令执行(RCE)面对各种过滤&#xff0c;骚姿势绕过总结 题目代码&#xff1a; <?php highlight_file(__FILE__); …

【算法练习】leetcode链表算法题合集

链表总结 增加表头元素倒数节点&#xff0c;使用快慢指针环形链表&#xff08;快慢指针&#xff09;合并有序链表&#xff0c;归并排序LRU缓存 算法题 删除链表元素 删除链表中的节点 LeetCode237. 删除链表中的节点 复制后一个节点的值&#xff0c;删除后面的节点&#x…

verilog 通过DPI-C调用C 流水灯模拟

verilog 通过DPI-C调用C简单示例&#xff0c; verillator模拟 ledloop.v module ledloop(input wire clk,output wire[3:0] LED );reg[31:0] cnt 32h00000000;always (posedge clk)cnt < cnt 1;assign LED 4b0001 << cnt[21:20]; endmodule电脑模拟较慢&#xff…

如何解决服务器CA证书过期的问题

一、问题的提出 最近在学习VPS&#xff0c;在Linux系统里给服务器安装某项服务时&#xff0c;在服务的log里看到下面的错误信息&#xff1a; failed to verify certificate: x509: certificate has expired or is not yet valid: current time 2023-12-25T04:42:38-05:00 is a…

java球队信息管理系统Myeclipse开发mysql数据库web结构java编程计算机网页项目

一、源码特点 java Web球队信息管理系统是一套完善的java web信息管理系统&#xff0c;对理解JSP java编程开发语言有帮助&#xff0c;系统具有完整的源代码和数据库&#xff0c;系统主要采用B/S模式开发。开发环境为TOMCAT7.0,Myeclipse8.5开发&#xff0c;数据库为Mysql5…

深度学习之RNN

1.循环神经网络 在时间t的时候&#xff0c;对于单个神经元来讲它的输出y(t)如下 wx是对于输入x的权重&#xff0c;wy是对于上一时刻输出的权重 所以循环神经网络有两个权重。 如果有很多这样的神经元并排在一起 则在t时刻的输出y为 这时输入输出都是向量 2.记忆单元 由于循…

java系列-CountDownLatch

CountDownLatch 不是一种锁&#xff0c;而是一种同步工具类&#xff0c;用于协调多个线程之间的操作。它并不是像 ReentrantLock 或 synchronized 关键字那样实现了锁定机制&#xff0c;而是通过一个计数器来实现线程的等待和通知。 具体来说&#xff0c;CountDownLatch 维护了…

车队试验的远程实时显示方案

风丘科技推出的数据远程实时显示方案更好地满足了客户对于试验车队远程实时监控的需求&#xff0c;并真正实现了试验车队的远程管理。随着新的数据记录仪软件IPEmotion RT和相应的跨平台显示解决方案的引入&#xff0c;让我们的客户端不仅可在线访问记录器系统状态&#xff0c;…

LaTeX 不同章的图片放在不同的文件夹

需求&#xff1a;在写长文档的时候&#xff0c;比如学位论文&#xff0c;每一章都有好几张图片&#xff0c;整个文档一共几十张甚至上百张图片&#xff0c;如果不分开放&#xff0c;想修改某一张图片的时候&#xff0c;找起来比较困难。所以&#xff0c;想把每一章的图片单独放…

git unable to create temporary file: No space left on device(git报错)

1.问题 1.1 vscode中npm run serve跑项目的时候&#xff0c;进度达到95%的时候一直卡着无进度&#xff1b; 1.2 git命令提交代码报错&#xff1b; 2.具体解决 这个错误通常表示你的磁盘空间已经满了&#xff0c;导致 Git 无法在临时目录中创建文件。2.1 清理磁盘空间&#xf…

LeetCode75| 区间集合

目录 435 无重叠区间 452 用最少的箭引爆气球 435 无重叠区间 class Solution { public:static bool cmp(vector<int>&a,vector<int>&b){return a[0] < b[0];}int eraseOverlapIntervals(vector<vector<int>>& intervals) {int res …

低代码平台在金融银行中的应用场景

随着数字化转型的推进&#xff0c;商业银行越来越重视技术在业务发展中的作用。在这个背景下&#xff0c;白码低代码平台作为一种新型的开发方式&#xff0c;正逐渐受到广大商业银行的关注和应用。白码低代码平台能够快速构建各类应用程序&#xff0c;提高开发效率&#xff0c;…

WebGoat 指定端口号

文章目录 新版本的 WebGoat旧版本 WebGoat 新版本的 WebGoat 使用 WEBGOAT_PORT 指定 WebGoat 的端口号 使用 WEBWOLF_PORT 指定 WebWolf 的端口号 java -DWEBGOAT_PORT8081 -jar webgoat-2023.8.jar java -DWEBGOAT_PORT8081 -DWEBWOLF_PORT9091 -jar webgoat-2023.8.jar W…

跨境电商引流真的很难吗?了解一下这些技巧!

随着全球电商市场的不断扩大&#xff0c;越来越多的企业开始涉足跨境电商领域&#xff0c;然而&#xff0c;与国内电商相比&#xff0c;跨境电商面临着诸多挑战&#xff0c;其中最大的难题之一就是如何有效地吸引潜在客户。 很多卖家觉得跨境电商引流非常困难&#xff0c;但实…

解析数据时代----驱动变革与重塑商业的力量

随着科技的飞速发展&#xff0c;我们正处在一个信息爆炸的时代。数据&#xff0c;作为这个时代的核心要素&#xff0c;已经渗透到各个领域&#xff0c;深刻影响着我们的生活、工作和商业模式。本文将深入解析数据时代的特点、影响以及如何应对数据带来的挑战&#xff0c;以适应…