Elasticsearch7.x——Cat命令详解

本文介绍了Elasticsearch的CatAPI,一个用于快速浏览和查询集群信息的工具,包括子目录、常用接口(如别名、分配、文档计数等)、参数选项以及各接口的具体功能和返回结果格式。

查看API

JSON格式非常适合计算机,虽然打印得很好,但用户试图在数 据中查找到关系时也会感到乏味。人类的眼睛,尤其是在看终端时, 需要的是紧凑和对齐的文本。/_cat旨在满足这一需求。

1、查看子目录

_cat/后不跟任何子节点,返回的结果是目录,也就是可用的 URL节点,这个功能是非常有用的,当忘记某个接口时可以先执行这 个接口。示例如下:

get /_cat

返回结果就是所有可用的Cat API:

/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates
/_cat/transforms
/_cat/transforms/{transform_id}

2、公共参数

可以多个参数一起使用,用&连接

GET /_cat/indices?v&s=store.size:desc

2.1、Verbose

每个命令都接受一个查询字符串参数v来打开详细输出。例如:

GET /_cat/master?v

返回:

id                     host      ip        node
Cc6ARDA6TY-poOdtxvsA6g 127.0.0.1 127.0.0.1 zhangchenglongdeMacBook-Pro.local

2.2、help

每个命令都接受一个查询字符串参数help,该参数将输出其可用 值。示例:

GET /_cat/master?help

返回:

id   |   | node id    
host | h | host name  
ip   |   | ip address 
node | n | node name 

2.3、h

每个命令都接受一个查询字符串参数h,该参数只强制显示这些 列。示例

GET /_cat/nodes?h=ip,port,heapPercent,name

返回:

127.0.0.1 9300 35 zhangchenglongdeMacBook-Pro.local

2.4、sort

指定输出的列进行排序,默认按照升序排序:

GET /_cat/indices/?v&s=pri,rep:desc

返回:

health status index                           uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   a                               G8WjS7PoQRG9kCQznaDmsg   1   1          1            0      3.4kb          3.4kb
yellow open   recipes                         agtHN2npS2GE90N81xtjEA   1   1          9            0      4.8kb          4.8kb
yellow open   b                               lnBia7kNQJOBAKvFLWefTg   1   1          1            0      3.6kb          3.6kb
yellow open   log                             H3bResC1QyK-9hdZQ0gs0g   1   1          1            0      4.3kb          4.3kb
yellow open   geo_shape   

2.5、format

指定响应返回的数据格式:text(默认),json,yaml,smile,cbor
(通过设置 Accept的HTTP头部的多媒体格式的优先级更高)

GET /_cat/master?format=json

返回:

[
  {
    "id" : "Cc6ARDA6TY-poOdtxvsA6g",
    "host" : "127.0.0.1",
    "ip" : "127.0.0.1",
    "node" : "zhangchenglongdeMacBook-Pro.local"
  }
]

3、常用接口

3.1、aliases——别名、过滤器、路由信息

显示别名,过滤器,路由信息:

GET /_cat/aliases?v

在这里插入图片描述

返回字段原文含义
aliasalias name别名
indexindex alias points to别名指向
filterfilter过滤器
routing.indexindex routing索引路由
routing.searchsearch routing搜索路由
is_write_indexwrite index写索引

3.2、allocation——分片数量、占用空间

显示每个节点分片数量、占用空间

GET /_cat/allocation?v

在这里插入图片描述

返回字段原文含义
shardsnumber of shards on node节点承载的分片数量
disk.indicsdisk used by ES indices索引占用的空间大小
disk.useddis used(total,not just ES)节点所在及其已使用的磁盘空间大小
disk.availdisk available节点可用空间大小
disk.totaltotal capacity of all volumes节点总空间大小
disk.percentpercent disk used节点磁盘占用百分比
hosthost of node节点host
ipip of noe节点ip
nodename of node节点名称

3.3、count——文档数量

显示索引文档的数量

GET /_cat/count?v

在这里插入图片描述

返回字段原文含义
epochseconds since 1970-01-01 00:00:00自标准时间(1970-01-01 00:00:00)以来的秒数
timestamptime in HH:MM:SS时分秒,utc时区
countthe document count文档总数

3.4、health——健康信息

查看集群健康状况

GET /_cat/health?v

在这里插入图片描述

返回字段原文含义
epochseconds since 1970-01-01 00:00:00自标准时间(1970-01-01 00:00:00)以来的秒数
timestamptime in HH:MM:SS时分秒,utc时区
clustercluster name集群名称
statushealth stauts集群状态
node.totaltotal number of nodes节点总数
node.datanumber of nodes that can store data数据节点总数
shardstotal number of shards分片总数
prinumber of primary shards主分片总数
relonumber of relocating nodes复制节点总数
initnumber of initializing nodes初始化节点总数
unassignnumber of unassigned shards未分配分片总数
pending_tasksnumber of pending tasks待定任务总数
max_task_wait_timewait time of longest task pending等待最长任务的等待时间
active_shards_percentactive number of shards in percent活动分片百分比

3.5、indices——索引信息

查看索引信息

GET /_cat/indices?v

在这里插入图片描述

返回字段原文含义
healthcurrent health status索引健康状态
statusopen/close status索引的开启状态
indexindex name索引名称
uuidindex uuid索引uuid
prinumber of primary shards索引主分片数
repnumber of replica shards所以副本分片数量
docs.countavailable docs索引中文档总数
docs.deleteddeleted docs索引中删除状态的文档
store.sizestore size of primaries & replicas主分片+副本分片的大小
pri.store.sizestore size of primaries主分片的大小

3.6、master——master节点信息

显示master节点信息

GET /_cat/master?v

在这里插入图片描述

返回字段原文含义
idnode id节点id
hosthost namehost
ipip addressip
nodenode name节点名称

3.7、nodeattrs——节点属性

显示node节点属性

GET /_cat/nodeattrs?v

在这里插入图片描述

返回字段原文含义
nodenode name节点名称
hosthost namehost
ipip addressip
attrarrribute description属性描述
valueattribute value属性值

3.8、nodes——节点信息

显示node节点信息

GET /_cat/nodes?v

在这里插入图片描述

返回字段原文含义
ipipip
hap.percentused heap堆内存占用百分比
ram.percentused machine memory ratio内存占用百分比
cpurecent cpuCPU占用百分比
load_1m1m load avg1分钟的系统负载
load_5m5m load avg5分钟的系统负载
load_15m15m load avg15分钟的系统负载
node.rolem:master eligible node, d:data node, i:ingest node, -:coordinating node onlynode节点的角色
master*:current master是否是master节点
namenode name节点名称

3.9、pending_tasks——等待任务

显示正在等待的任务

GET /_cat/pending_tasks?v

在这里插入图片描述

返回字段原文含义
insertOrdertask insertion order任务插入顺序
timeInQueuehow long task has been in queue任务排队了多长时间
prioritytask priority任务优先级
sourcetask source任务源

3.10、plugins——插件信息

显示节点上的插件

GET /_cat/plugins?v

在这里插入图片描述

返回字段原文含义
namenode name节点名称
componentcomponent插件名称
versioncomponent version插件版本

3.11、recovery——索引碎片恢复视图

显示正在进行和先前完成的索引碎片恢复的视图

GET /_cat/recovery?format=json

返回:

[
  {
    "index" : "log",
    "shard" : "0",
    "time" : "22ms",
    "type" : "existing_store",
    "stage" : "done",
    "source_host" : "n/a",
    "source_node" : "n/a",
    "target_host" : "127.0.0.1",
    "target_node" : "zhangchenglongdeMacBook-Pro.local",
    "repository" : "n/a",
    "snapshot" : "n/a",
    "files" : "0",
    "files_recovered" : "0",
    "files_percent" : "100.0%",
    "files_total" : "4",
    "bytes" : "0",
    "bytes_recovered" : "0",
    "bytes_percent" : "100.0%",
    "bytes_total" : "4498",
    "translog_ops" : "0",
    "translog_ops_recovered" : "0",
    "translog_ops_percent" : "100.0%"
  },
  ...
]
返回字段原文含义
indexindex name索引名称
shardshard name分片名称
timerecovery time恢复时间
typerecovery type恢复类型
stagerecovery stage恢复阶段
source_hostsource host源主机
source_nodesource node name源节点名称
target_hosttarget host目标主机
target_nodetarget node name目标节点名称
repositoryrepository仓库
snapshotsnpshot快照
filesnumber offiles to recover要恢复的文件数
files_recoveredfiles recovered已恢复的文件数
files_perventpervent of files recoverd恢复文件百分比
files_totaltotal number of files文件总数
bytesnumber of bytes to recover要恢复的字节数
bytes_recoveredbytes recovered已恢复的字节数
bytes_percentpercent of bytes recovered恢复字节百分比
bytes_totaltotal number of bytes字节总数
translog_opsnumber of translog ops to recover要恢复的translog操作数
translog_ops_recoveredtranslog ops recovered已恢复的translog操作数
translog_ops_percentpercent of transog ops recovered恢复的translog操作的百分比

3.12、segments——分段信息

显示分片中的分段信息

GET /_cat/segments?v

在这里插入图片描述

返回字段原文含义
indexindex name索引名称
shardshard name分片名称
prirepprimary or replica主分片还是副本分片
ipip of node where it lives所在节点ip
segmentsegment namesegments段名
generationsegment generation分段生成
docs.countnumber of docs in segment段中的文档数
docs.deletednumber of deleted docs in segment段中删除的文档数
sizesegment size in bytes段大小,以字节为单位
size.memorysegment memory in bytes段内存大小,以字节为单位
committedis segment committed段是否已提交
searchableis segment searched段是否可搜索
versionversion版本
compoundis segment compoundcompound模式

3.13、shards——分片信息

显示索引分片信息

GET /_cat/shards?v

在这里插入图片描述

返回字段原文含义
indexindex name索引名称
shardshard name分片序号
prirepprimary or replica分片类型,p表示是主分片,r表示是复制分片
stateshard state分片状态
docsnumber of docs in shard该分片存放的文档数量
storestore size of shard(how much disk it uses)该分片占用的存储空间大小
ipip of node where it lives该分片所在服务器ip
nodename of node where it该分片所在的节点名称

3.14、thread_pool——线程池信息

显示线程池信息

GET /_cat/thread_pool?v

在这里插入图片描述

返回字段原文含义
node_namenode name节点名称
namethread pool name线程池名称
activenumber of active treads活跃线程数
queuenumber of tasks currently in queue当前队列中的任务数
rejectednumber of rejected tasks被拒绝的任务数

3.15、templates——模板信息

显示模板信息

GET /_cat/templates?v

在这里插入图片描述

返回字段原文含义
nametemplate name模板名称
index_patternstemplate index patterns模板匹配规则
ordertemplate application order number模板优先级
versionversion模板版本
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值