--- title: "查看索引别名" date: 2026-02-26 lastmod: 2026-02-26 description: "以表格形式查看索引别名信息,简洁易读" tags: ["索引管理", "别名", "索引别名"] summary: "以表格形式展示索引别名信息,适合人工查看和快速检查。 API # GET /_cat/aliases GET /_cat/aliases/{alias} API 的作用 # 该 API 以表格形式返回索引别名信息,提供人类可读的视图。 vs GET /_aliases # API 返回格式 适用场景 GET /_aliases JSON 程序化处理、API 集成 GET /_cat/aliases 表格 人工查看、命令行检查 表格列说明 # 列 描述 alias 别名名称 index 别名指向的索引 filter 过滤器(* 表示有过滤器,- 表示无) routing." --- 以表格形式展示索引别名信息,适合人工查看和快速检查。 ## API ``` GET /_cat/aliases GET /_cat/aliases/{alias} ``` ## API 的作用 该 API 以表格形式返回索引别名信息,提供人类可读的视图。 ### vs GET /_aliases | API | 返回格式 | 适用场景 | |-----|----------|----------| | `GET /_aliases` | JSON | 程序化处理、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 | 输出格式:`text`、`json`、`yaml` | | `s` | 列表 | 否 | - | 排序方式 | | `time` | 枚举值 | 否 | ms | 时间单位:`ms`、`s`、`m`、`h`、`d` | ## 示例 ### 基本查看 ```bash 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 - ``` ### 显示列标题 ```bash 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 ``` ### 查看特定别名 ```bash GET /_cat/aliases/logs ``` ### 按索引过滤 ```bash GET /_cat/aliases?index=logs-* ``` ### JSON 格式输出 ```bash GET /_cat/aliases?format=json ``` **响应示例:** ```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 格式输出 ```bash GET /_cat/aliases?format=yaml ``` **响应示例:** ```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" ``` ### 自定义显示列 ```bash 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 - ``` ### 按别名名称排序 ```bash GET /_cat/aliases?v&s=alias ``` ### 按索引名称排序 ```bash GET /_cat/aliases?v&s=index:desc ``` ### 查看带过滤器的别名 ```bash GET /_cat/aliases?v | grep '*' ``` ### 只返回本地信息 ```bash GET /_cat/aliases?local=true ``` ### 查看帮助 ```bash 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) ``` ### 检查写入索引 ```bash GET /_cat/aliases?v | grep 'true$' ``` ### 组合过滤 ```bash GET /_cat/aliases?index=logs-*&format=json&h=alias,index,is_write_index ``` ## 响应字段说明 ### 表格列详解 | 列 | 描述 | 可能值 | |------|------|--------| | `alias` | 别名名称 | 别名字符串 | | `index` | 索引名称 | 索引字符串 | | `filter` | 过滤器状态 | `-`(无过滤器)、`*`(有过滤器) | | `routing.index` | 索引路由 | 路由值或 `-`(未设置) | | `routing.search` | 搜索路由 | 路由值或 `-`(未设置) | | `is_write_index` | 写入索引标记 | `true`、`false`、`-`(未设置) | ## 使用场景 ### 场景 1:快速检查别名配置 ```bash GET /_cat/aliases?v ``` ### 场景 2:验证别名切换 ```bash # 检查 products 别名是否指向新索引 GET /_cat/aliases/products?v ``` ### 场景 3:查找写入索引 ```bash GET /_cat/aliases?v | grep 'true' ``` ### 场景 4:审计别名配置 ```bash # 导出所有别名配置 GET /_cat/aliases?format=json > aliases_audit.json ``` ### 场景 5:检查路由配置 ```bash GET /_cat/aliases?v&h=alias,index,routing.index,routing.search ``` ### 场景 6:监控别名数量 ```bash # 统计别名总数 GET /_cat/aliases?format=json | jq '. | length' ``` ### 场景 7:查找多索引别名 ```bash # 查找指向多个索引的别名 GET /_cat/aliases?format=json | jq -r 'group_by(.alias) | select(length > 1)' ``` ## 常用查询模式 ### 查找所有写入索引 ```bash GET /_cat/aliases?v&h=alias,index | grep 'true' ``` ### 查找带过滤器的别名 ```bash GET /_cat/aliases?v | grep '*' ``` ### 按别名分组查看 ```bash GET /_cat/aliases?v&s=alias,index ``` ### 查找特定索引的别名 ```bash GET /_cat/aliases?index=my_index*&v ``` ### 检查别名一致性 ```bash # 对比别名配置差异 GET /_cat/aliases?format=json | jq -r '.alias + " => " + .index' | sort ``` ## 注意事项 1. **格式选择**:默认文本格式适合人工查看,JSON 适合程序处理 2. **排序**:使用 `s` 参数可以按任意列排序 3. **列选择**:使用 `h` 参数只显示需要的列 4. **性能**:大量别名时考虑过滤或分页 5. **本地信息**:local=true 可能不反映最新集群状态 ## 最佳实践 ### 1. 生产环境检查 ```bash # 定期检查关键别名配置 GET /_cat/aliases/products,orders,customers?v ``` ### 2. 别名迁移验证 ```bash # 迁移前后对比 GET /_cat/aliases/my_alias?format=json ``` ### 3. 自动化脚本 ```bash #!/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. 监控告警 ```bash # 检查关键别名是否存在 if ! curl -s 'localhost:9200/_cat/aliases/critical_alias' | grep -q 'critical_alias'; then echo "ALERT: critical_alias not found!" fi ```