获取指定规则库(规则仓库)的详细信息和配置。
API 格式 #
GET .match_rules/_doc/{repo_id}
API 作用 #
该 API 用于检索指定规则库的完整信息,包括:
- 规则库名称和描述
- 规则内容(表达式列表)
- 版本和状态信息
- 编译信息和编译节点
- 数值字段声明和复合索引定义
API 参数 #
路径参数 #
| 参数 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
{repo_id} | String | 是 | - | 规则库的唯一标识符 |
查询参数 #
| 参数 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
_source | String/Array | 否 | 所有字段 | 指定要返回的字段 |
_source_excludes | String/Array | 否 | - | 指定要排除的字段(如 rules 可排除大文本内容) |
routing | String | 否 | - | 路由参数 |
preference | String | 否 | - | 分片偏好 |
realtime | Boolean | 否 | true | 是否执行实时搜索 |
请求示例 #
获取规则库完整信息 #
GET .match_rules/_doc/security_v1
仅获取元数据(排除规则内容) #
GET .match_rules/_doc/security_v1?_source_excludes=rules
获取特定字段 #
GET .match_rules/_doc/security_v1?_source=name,version,status,total_rules
响应示例 #
成功响应 #
{
"_index": ".match_rules",
"_id": "security_v1",
"_version": 2,
"_seq_no": 1,
"_primary_term": 1,
"found": true,
"_source": {
"name": "安全规则库",
"description": "用于安全事件分类的规则库",
"tags": ["security", "content-filter"],
"rules": "枪 or 手枪 or 步枪\t#0#涉枪武器关键词\nAK47 or AK-47 or M16\t#1#枪支型号",
"version": "2",
"status": "compiled",
"compiled_at": "2026-01-07T08:00:00Z",
"total_rules": 2,
"compiled_nodes": ["node-1", "node-2", "node-3"],
"fields": ["price", "score"],
"composite": ["(price,score)"],
"created": "2025-12-31T10:00:00Z",
"updated": "2025-12-31T10:15:00Z"
}
}
未找到响应 #
{
"_index": ".match_rules",
"_id": "nonexistent_repo",
"_version": 1,
"found": false
}
索引不存在错误 #
{
"error": {
"root_cause": [
{
"type": "index_not_found_exception",
"reason": "no such index [.match_rules]",
"resource.type": "index_or_alias",
"resource.id": ".match_rules",
"index": ".match_rules"
}
],
"type": "index_not_found_exception",
"reason": "no such index [.match_rules]",
"status": 404
}
}
响应字段说明 #
顶层字段 #
| 字段 | 类型 | 描述 |
|---|---|---|
_index | String | 索引名称(固定为 .match_rules) |
_id | String | 文档 ID(即 repo_id) |
_version | Integer | 文档版本号 |
_seq_no | Integer | 序列号 |
_primary_term | Integer | 主术语 |
found | Boolean | 是否找到文档 |
_source | Object | 规则库的源数据 |
_source 对象字段 #
| 字段 | 类型 | 描述 |
|---|---|---|
name | String | 规则库名称 |
description | String | 规则库描述 |
tags | String[] | 用于分类的标签 |
rules | String | 规则文本内容(格式:每行 表达式\t#偏移量#描述) |
version | String | 规则库版本(每次导入递增) |
status | String | 编译状态:pending(待编译)、compiled(已编译)、partial(部分编译)、failed(失败) |
compiled_at | String | 最后成功编译的时间戳 |
total_rules | Integer | 规则库中的规则总数 |
compiled_nodes | String[] | 已编译规则的节点列表 |
fields | String[] | 编译期间声明的数值字段(用于数值匹配) |
composite | String[] | 复合索引定义(用于性能优化) |
created | String | 规则库创建时间戳 |
updated | String | 最后更新时间戳 |
error_message | String | 如果编译失败,显示错误消息 |
使用建议 #
- 排除大字段:规则内容可能很大,建议使用
_source_excludes=rules仅获取元数据 - 系统索引:
.match_rules是系统索引,由规则插件管理 - 文档 ID:每个规则库存储为单个文档,
repo_id作为文档 ID - 权限要求:访问
.match_rules索引需要相应权限
使用场景 #
- 检查规则库状态和版本
- 验证规则是否已编译
- 查看规则库的编译节点分布
- 获取规则库元数据而不下载完整规则内容





