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

获取指定规则库(规则仓库)的详细信息和配置。

API 格式 #

GET .match_rules/_doc/{repo_id}

API 作用 #

该 API 用于检索指定规则库的完整信息,包括:

  • 规则库名称和描述
  • 规则内容(表达式列表)
  • 版本和状态信息
  • 编译信息和编译节点
  • 数值字段声明和复合索引定义

API 参数 #

路径参数 #

参数类型是否必填默认值描述
{repo_id}String-规则库的唯一标识符

查询参数 #

参数类型是否必填默认值描述
_sourceString/Array所有字段指定要返回的字段
_source_excludesString/Array-指定要排除的字段(如 rules 可排除大文本内容)
routingString-路由参数
preferenceString-分片偏好
realtimeBooleantrue是否执行实时搜索

请求示例 #

获取规则库完整信息 #

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
  }
}

响应字段说明 #

顶层字段 #

字段类型描述
_indexString索引名称(固定为 .match_rules
_idString文档 ID(即 repo_id
_versionInteger文档版本号
_seq_noInteger序列号
_primary_termInteger主术语
foundBoolean是否找到文档
_sourceObject规则库的源数据

_source 对象字段 #

字段类型描述
nameString规则库名称
descriptionString规则库描述
tagsString[]用于分类的标签
rulesString规则文本内容(格式:每行 表达式\t#偏移量#描述
versionString规则库版本(每次导入递增)
statusString编译状态:pending(待编译)、compiled(已编译)、partial(部分编译)、failed(失败)
compiled_atString最后成功编译的时间戳
total_rulesInteger规则库中的规则总数
compiled_nodesString[]已编译规则的节点列表
fieldsString[]编译期间声明的数值字段(用于数值匹配)
compositeString[]复合索引定义(用于性能优化)
createdString规则库创建时间戳
updatedString最后更新时间戳
error_messageString如果编译失败,显示错误消息

使用建议 #

  1. 排除大字段:规则内容可能很大,建议使用 _source_excludes=rules 仅获取元数据
  2. 系统索引.match_rules 是系统索引,由规则插件管理
  3. 文档 ID:每个规则库存储为单个文档,repo_id 作为文档 ID
  4. 权限要求:访问 .match_rules 索引需要相应权限

使用场景 #

  • 检查规则库状态和版本
  • 验证规则是否已编译
  • 查看规则库的编译节点分布
  • 获取规则库元数据而不下载完整规则内容