📣 极限科技诚招搜索运维工程师(Elasticsearch/Easysearch)- 全职/北京 👉 : 立即申请加入

以表格形式展示索引别名信息,适合人工查看和快速检查。

API #

GET /_cat/aliases
GET /_cat/aliases/{alias}

API 的作用 #

该 API 以表格形式返回索引别名信息,提供人类可读的视图。

vs GET /_aliases #

API返回格式适用场景
GET /_aliasesJSON程序化处理、API 集成
GET /_cat/aliases表格人工查看、命令行检查

表格列说明 #

描述
alias别名名称
index别名指向的索引
filter过滤器(* 表示有过滤器,- 表示无)
routing.index索引路由值
routing.search搜索路由值
is_write_index是否为写入索引

API 的参数 #

路由参数 #

参数类型是否必填描述
{alias}字符串要显示的别名名称

Query String 参数 #

参数类型是否必填默认值描述
alias字符串全部要显示的别名名称
index字符串全部要显示的索引名称
local布尔值false是否只返回本地信息
h列表默认列显示的列名
help布尔值false显示帮助信息
v布尔值false显示列标题
format枚举值text输出格式:textjsonyaml
s列表-排序方式
time枚举值ms时间单位:mssmhd

示例 #

基本查看 #

GET /_cat/aliases

输出示例:

alias       index          filter routing.index routing.search is_write_index
logs        logs-2024-01              -              -              true
logs        logs-2024-02              -              -              false
errors      logs                     *              -              -
user_logs   logs-2024-01              -              user1         -

显示列标题 #

GET /_cat/aliases?v

输出示例:

alias => alias name
index => index the alias points to
filter => filter
routing.index => index routing
routing.search => search routing
is_write_index => write index

alias       index          filter routing.index routing.search is_write_index
logs        logs-2024-01              -              -              true

查看特定别名 #

GET /_cat/aliases/logs

按索引过滤 #

GET /_cat/aliases?index=logs-*

JSON 格式输出 #

GET /_cat/aliases?format=json

响应示例:

[
  {
    "alias": "logs",
    "index": "logs-2024-01",
    "filter": "-",
    "routing.index": "-",
    "routing.search": "-",
    "is_write_index": "true"
  },
  {
    "alias": "logs",
    "index": "logs-2024-02",
    "filter": "-",
    "routing.index": "-",
    "routing.search": "-",
    "is_write_index": "false"
  }
]

YAML 格式输出 #

GET /_cat/aliases?format=yaml

响应示例:

- alias: "logs"
  index: "logs-2024-01"
  filter: "-"
  routing.index: "-"
  routing.search: "-"
  is_write_index: "true"
- alias: "logs"
  index: "logs-2024-02"
  filter: "-"
  routing.index: "-"
  routing.search: "-"
  is_write_index: "false"

自定义显示列 #

GET /_cat/aliases?v&h=alias,index,is_write_index

输出示例:

alias       index          is_write_index
logs        logs-2024-01   true
logs        logs-2024-02   false
errors      logs           -

按别名名称排序 #

GET /_cat/aliases?v&s=alias

按索引名称排序 #

GET /_cat/aliases?v&s=index:desc

查看带过滤器的别名 #

GET /_cat/aliases?v | grep '*'

只返回本地信息 #

GET /_cat/aliases?local=true

查看帮助 #

GET /_cat/aliases?help

输出示例:

aliases     Show information about index aliases
Aliases:    []

Headers:    [alias, index, filter, routing.index, routing.search, is_write_index]

Parameters:
  alias (a): Comma-separated list of aliases to show
  index (i): Comma-separated list of indexes to show
  local (l): Return local information, do not retrieve the state from master node
  h (h): Comma-separated list of column names to display
  help (h): Show help
  s (s): Comma-separated list of column names or column aliases to sort by
  v (v): Verbose mode. Display column headers.
  format (f): Output format (text, json, yaml)

检查写入索引 #

GET /_cat/aliases?v | grep 'true$'

组合过滤 #

GET /_cat/aliases?index=logs-*&format=json&h=alias,index,is_write_index

响应字段说明 #

表格列详解 #

描述可能值
alias别名名称别名字符串
index索引名称索引字符串
filter过滤器状态-(无过滤器)、*(有过滤器)
routing.index索引路由路由值或 -(未设置)
routing.search搜索路由路由值或 -(未设置)
is_write_index写入索引标记truefalse-(未设置)

使用场景 #

场景 1:快速检查别名配置 #

GET /_cat/aliases?v

场景 2:验证别名切换 #

# 检查 products 别名是否指向新索引
GET /_cat/aliases/products?v

场景 3:查找写入索引 #

GET /_cat/aliases?v | grep 'true'

场景 4:审计别名配置 #

# 导出所有别名配置
GET /_cat/aliases?format=json > aliases_audit.json

场景 5:检查路由配置 #

GET /_cat/aliases?v&h=alias,index,routing.index,routing.search

场景 6:监控别名数量 #

# 统计别名总数
GET /_cat/aliases?format=json | jq '. | length'

场景 7:查找多索引别名 #

# 查找指向多个索引的别名
GET /_cat/aliases?format=json | jq -r 'group_by(.alias) | select(length > 1)'

常用查询模式 #

查找所有写入索引 #

GET /_cat/aliases?v&h=alias,index | grep 'true'

查找带过滤器的别名 #

GET /_cat/aliases?v | grep '*'

按别名分组查看 #

GET /_cat/aliases?v&s=alias,index

查找特定索引的别名 #

GET /_cat/aliases?index=my_index*&v

检查别名一致性 #

# 对比别名配置差异
GET /_cat/aliases?format=json | jq -r '.alias + " => " + .index' | sort

注意事项 #

  1. 格式选择:默认文本格式适合人工查看,JSON 适合程序处理
  2. 排序:使用 s 参数可以按任意列排序
  3. 列选择:使用 h 参数只显示需要的列
  4. 性能:大量别名时考虑过滤或分页
  5. 本地信息:local=true 可能不反映最新集群状态

最佳实践 #

1. 生产环境检查 #

# 定期检查关键别名配置
GET /_cat/aliases/products,orders,customers?v

2. 别名迁移验证 #

# 迁移前后对比
GET /_cat/aliases/my_alias?format=json

3. 自动化脚本 #

#!/bin/bash
# 检查写入索引是否正确
WRITE_INDEX=$(curl -s 'localhost:9200/_cat/aliases/my_alias?format=json' | jq -r '.[] | select(.is_write_index == "true") | .index')
echo "Write index: $WRITE_INDEX"

4. 监控告警 #

# 检查关键别名是否存在
if ! curl -s 'localhost:9200/_cat/aliases/critical_alias' | grep -q 'critical_alias'; then
  echo "ALERT: critical_alias not found!"
fi