_cat的命令公共参数

查看master节点信息:GET _cat/master?v

返回的列标题的详细解释信息。每个cat命令后面都可以加上help,查看帮助信息。

GET _cat/master?help

headers

每个命令都接受一个查询字符串参数h,该参数仅强制显示那些列。&v显示列

数字格式

许多命令提供了几种类型的数字输出,可以是字节,大小或时间值。 默认情况下,这些类型是人类格式的,例如3.5mb而不是3763212。人类值不能进行数字排序,因此要在顺序重要的地方使用这些值,可以对其进行更改。

如果要更改时间单位,请使用时间参数。
如果要更改尺寸单位,请使用size参数。
如果要更改字节单位,请使用bytes参数。

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

sort排序

每个命令都接受一个查询字符串参数s,该参数按指定为参数值的列对表进行排序。 列可以通过名称或别名来指定,并以逗号分隔的字符串形式提供。 默认情况下,排序以升序方式进行。 将:desc附加到一列将颠倒该列的顺序。 :asc也被接受,但表现出与默认排序顺序相同的行为。

例如,使用排序字符串s = column1,column2:desc,column3,将按列1的升序,按列2的降序和按列3的升序对表进行排序。

GET _cat/templates?v&s=order:desc,index_patterns

format输出格式

#支持的输出格式有json,test,yaml等
#默认以text格式输出
#以json格式输出 format=json&pretty

GET _cat/indices?v&h=index,docs.count,store.size&bytes=kb&format=json&pretty

#以yaml格式输出 format=yaml&pretty

GET _cat/indices?v&h=index,docs.count,store.size&bytes=kb&format=yaml&pretty

 

_cat/health 查看集群健康状态

GET _cat/health?v

描述:

cluster ,集群名称

status,集群状态 green代表健康;yellow代表分配了所有主分片,但至少缺少一个副本,此时集群数据仍旧完整;red代表部分主分片不可用,可能已经丢失数据。

node.total,代表在线的节点总数量

node.data,代表在线的数据节点的数量

shards, active_shards 存活的分片数量

pri,active_primary_shards 存活的主分片数量 正常情况下 shards的数量是pri的两倍。

relo, relocating_shards 迁移中的分片数量,正常情况为 0

init, initializing_shards 初始化中的分片数量 正常情况为 0

unassign, unassigned_shards 未分配的分片 正常情况为 0

pending_tasks,准备中的任务,任务指迁移分片等 正常情况为 0

max_task_wait_time,任务最长等待时间

active_shards_percent,正常分片百分比 正常情况为 100%

_cat/nodes 查看集群节点和磁盘剩余

GET _cat/nodes?v

描述:

heap.percent ,堆内存占用百分比

ram.percent ,内存占用百分比

cpu ,CPU占用百分比

load_1m load_5m load_15m  ,一分钟五分钟十五分钟负载

node.role , m:master eligible node, d:data node, i:ingest node。master *表示节点是集群中的主节点current master 

name ,节点名

_cat/indices 查看索引情况

GET _cat/indices?v

GET _cat/indices/{index}:GET _cat/indices/my_index1?v

描述:

                1)health \ status \index          

                2)how many shards make up an index,  (pri:主分配, rep:副本分片)

                3)the number of docs,  (docs.count :文档数)

                4)deleted docs,   (删除文档数)

                5)and total store size (all shards including replicas).  全部分片存储大小

                6)primary store size,  主分片存储大小

_cat/allocation 查看分配

#查看每个数据节点上的分片数(shards),以及每个数据节点磁盘剩余

GET _cat/allocation?v

描述:

          1)shards ,节点说承载的分片数

          2) disk.indices ,索引占用的空间大小

         3)disk.used ,节点所在机器已使用磁盘空间

         4)disk.avail ,磁盘可用容量

         5)disk.total, 磁盘总容量

         6)disk.percent  ,磁盘便用率

         7)ip ,节点所属机器IP地址

         8)node ,节点名

_cat/plugins 查看每个节点正在运行的插件

GET _cat/plugins?v

_cat/nodeattrs 查看每个节点的自定义属性

GET /_cat/nodeattrs?v

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

_cat/recovery 查看索引分片的恢复视图 

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

#只要索引分片移动到群集中的其他节点,就会发生恢复事件

GET _cat/recovery?v&format=json&pretty

_cat/recovery/{index}:GET _cat/recovery/my_index1?v\

/_cat/recovery?active_only&v 可以看到数据同步进度

返回字段

原文

含义

index

index name

索引名称

shard

shard name

分片名称

time

recovery time

恢复时间

type

recovery type

恢复类型

stage

recovery stage

恢复阶段

source_host

source host

源主机

source_node

source node name

源节点名称

target_host

target host

目标主机

target_node

target node name

目标节点名称

repository

repository

仓库

snapshot

snapshot

快照

files

number of files to recover

要恢复的文件数

files_recovered

files recovered

已恢复的文件数

files_percent

percent of files recovered

恢复文件百分比

files_total

total number of files

文件总数

bytes

number of bytes to recover

要恢复的字节数

bytes_recovered

bytes recovered

已恢复的字节数

bytes_percent

percent of bytes recovered

恢复字节百分比

bytes_total

total number of bytes

字节总数

translog_ops

number of translog ops to recover

要恢复的translog操作数

translog_ops_recovered

translog ops recovered

已恢复的translog操作数

translog_ops_percent

percent of translog ops recovered

恢复的translog操作的百分比

_cat/fielddata 查看每个数据节点上fielddata当前占用的堆内存


全文检索用倒排索引非常合适;但过滤、分组聚合、排序这些操作,正排索引更合适。
ES中引入了fielddata的数据结构用来做正排索引。如果需要对某一个字段排序、分组聚合、过滤,则可将字段设置成fielddata。
默认情况下:
  text类型的字段是不能分组及排序的,如需要则需要开启该字段的fielddata=true,但是这样耗费大量的内存,不建议这么使用。
  keyword类型默认可分组及排序。

fielddata默认是采用懒加载的机制加载到堆内存中。当某个字段基数特别大,可能会出现OOM。

GET _cat/fielddata?v&h=node,field,size

#对某一字段进行查看:GET _cat/fielddata/{fields}

GET _cat/fielddata?v&h=node,field,size&fields=kibana_stats.kibana.uuid

_cat/repositories 和 _cat/snapshots 查看注册的快照仓库

GET _cat/repositories?v

GET _snapshot
GET _snapshot/_status
GET _cat/snapshots

_cat/pending_tasks 显示正在等待的任务

一般cpu负载过高,可以排查还有多少任务在排队等待

GET _cat/pending_tasks?v

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

_cat/segments 分段信息

显示分片中的分段信息

GET _cat/segments?v&format=json&pretty

_cat/segments/{index}:GET _cat/segments/my_index1?v

查看segment总的情况:get cat/segment 查看节点的segment总占用内存情况(sm):GET _cat/nodes?v&h=ip,ram.percent,sm 某查看索引的segment:get index/segment:

返回字段原文含义
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模式

_cat/shards 分片 

显示索引分片信息

GET _cat/shards?v

GET _cat/shards/{index}:GET _cat/shards/my_index1?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该分片所在的节点名称

_cat/thread_pool 线程池 

显示线程池信息

GET _cat/thread_pool?v

GET _cat/thread_pool/{thread_pools}:GET _cat/thread_pool/get?v

/_cat/thread_pool/search?v&h=node_name,name,active,rejected,completed

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

_cat/templates 模板 

es提供template功能的出发点在哪里呢? 作为NoSQL数据库, ES在数据入库前是不做schema设定的, 也就是不限定数据字段.这对日志类型的数据来说, 是个利好的场景. 但是这种不设定schema的做法, 有时有太过自由. 有些业务场景, 我们需要预先设定field的分词方式. 这时固然可以使用mappings解决. 但是业务接入前要通知一下,先建个索引, 想想有点不智能. 有没有更灵活一点的做法呢? templates

template中规定了数据的存储格式、分片数量等信息。
template大致分成setting和mappings两部分:
1. settings主要作用于index的一些相关配置信息,如分片数、副本数,tranlog同步条件、refresh等。
2. mappings主要是一些说明信息,大致又分为_all、_source、prpperties这三部分:
     (1) _all:主要指的是AllField字段,我们可以将一个或多个都包含进来,在进行检索时无需指定字段的情况下检索多个字段。设置“_all" : {"enabled" : true}
     (2) _source:主要指的是SourceField字段,Source可以理解为ES除了将数据保存在索引文件中,另外还有一份源数据。_source字段在我们进行检索时相当重要,如果在{"enabled" : false}情况下默认检索只会返回ID, 你需要通过Fields字段去到索引中去取数据,效率不是很高。但是enabled设置为true时,索引会比较大,这时可以通过Compress进行压缩和inclueds、excludes来在字段级别上进行一些限制,自定义哪些字段允许存储
     (3) properties:这是最重要的步伐,主要针对索引结构和字段级别上的一些设置。

GET _cat/templates?v

返回字段原文含义
nametemplate name模板名称
index_patternstemplate index patterns模板匹配规则
ordertemplate application order number模板优先级
versionversion模板版本
   

创建templates:

PUT _template/template_1
{
  "template" : "te*",
   "settings" : {
    "number_of_shards" : 1,
    "index.number_of_replicas":2
},
"mappings" : {
    "type1" : {
        "_source" : { "enabled" : false }
    }
}
}

#查看template_1这个模板的详情
GET _template/template_1?pretty

#添加一条数据。要把自动创建索引功能开启。不然报错:[action.auto_create_index] contains [-*] which forbids automatic creation of the index
PUT template_test/_doc/1?pretty
{
  "user" : "kimchy",
  "post_date" : "2009-11-15T14:12:12",
  "message" : "trying out Elasticsearch"
}

#查看索引mapping
GET template_test/_mapping

#查看索引settings
GET template_test/_settings

#查看所有模板的mapping、settings等详情
GET _template

#查看每个模板的详情
GET _cat/templates?v

#template_test的其他settings并没有设置,但是沿用了aliyun_default_index_template 这个模板的
GET _template/aliyun_default_index_template 

 

_cat/master 查看主节点

显示master节点信息

GET _cat/master?v

id                     host          ip            node
hgbRZIBNSoyCcb3E15dlNA 10.61.149.199 10.61.149.199 10.61.149.199
返回字段原文含义
idnode id节点id
hosthost namehost
ipip addressip
nodenode name

节点名称

_cat/aliases 别名

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

GET _cat/aliases?v

alias               index                          filter routing.index routing.search is_write_index
goods_order 		goods_order_2020-01-25 -      -             -              -

_cat/count 文档数 

查看整个集群的doc的总数,以及单个索引的总数

GET _cat/count

#某个索引文档数

GET _cat/count/{index}:GET _cat/count/my_index1?v

#某类索引文档数

GET _cat/count/.monitoring*?v 

_nodes/stats  集群监控api

GET /_nodes/stats

返回所有节点统计信息。

GET /_nodes/<node_filter>/stats

 返回节点过滤器指定节点的统计信息。

GET /_nodes/stats/<metrics>
GET /_nodes/stats?metric=<metrics>

metrics

指标    说明
indices    索引统计信息,包括大小、文档数量、索引和删除次数、查询次数等。
fs    文件系统信息,包括数据路径、空闲磁盘大小等。
http    http连接信息,包括当前连接数、总共连接数。
jvm    JVM统计信息,包括内存池信息、垃圾收集、缓冲池、加载/卸载类的数量。
os    操作系统信息,包括平均负载、内存等。
process    进程统计信息,包括内存消耗、cpu使用情况、打开文件描述符。
thread_pool    每个线程池的统计信息,包括当前大小,队列大小、拒绝的任务数等。
transport    集群通信的传输统计信息,包括接收和发送的字节数等。
breaker    熔断器的统计信息。
discovery    自动发现统计信息。
ingest    ingest预处理统计信息。
adaptive_selection    自适应副本选择的统计信息。

当metrics为indices,还可以通过路径参数指定想要返回的索引指标。

GET /_nodes/stats/indices/<index_metrics>

 返回所有节点指定的索引指标统计信息。

GET /_nodes/<node_filter>/stats/indices/<index_metrics>

返回节点过滤器指定节点的指定的索引指标统计信息。

index_metrics可选值为docs、store、indexing、get、search、merges、refresh、flush、warmer、query_cache、fielddata、completion、segments、translog、request_cache、recovery。

当返回结果包含indices时,还接受如下查询参数:
参数    说明
fielddata_fields    逗号分隔的要包含在indices中fielddata下的字段列表,接受通配符表达式。
groups    逗号分隔的要包含在indices返回结果中search统计信息中的分组,只对search有效。
level    当返回节点包含indices指标时,统计信息是否按node、indices、shards级别进行聚合,默认为node,当level值为indices或shards时,返回结果indices中,会额外返回以索引或分片进行聚合的统计信息indices或shards。
types    逗号分隔的文档类型列表,用于指定indices指标中indexing统计的文档类型。如果指定了types,则indices返回结果indexing中会额外返回以文档类型进行聚合的统计信息types。如果指定为_all,则会对所有的类型分别进行统计。
timeout    等待响应的超时时间,如果超时时间内没有收到响应,则请求失败并返回错误,默认为30s。
include_segment_file_sizes    如果为true,则indices返回结果的segments中会额外返回索引文件的磁盘使用情况file_sizes,默认为false。

官网每个指标详解:https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-stats.html

_nodes/hot_threads 热线程

GET /_nodes/hot_threads
GET /_nodes/<node_id>/hot_threads

详解博客:https://elastic.blog.csdn.net/article/details/109567666

查看索引变红的原因

GET /_cluster/allocation/explain

 

 

 

 

 

 

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐