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

获取系统中所有规则库(规则仓库)的列表和概要信息。

API 格式 #

GET .match_rules/_search
POST .match_rules/_search

API 作用 #

该 API 用于列出所有可用的规则库,支持:

  • 查看所有规则库
  • 按状态、标签等条件过滤
  • 分页浏览规则库
  • 获取规则库的元数据信息

API 参数 #

查询参数 #

参数类型是否必填默认值描述
qString-全文搜索查询
fromInteger0分页起始偏移量
sizeInteger10每页返回的文档数量
sortString-排序字段和方式
_sourceString/Array所有字段返回的字段列表
_source_excludesString/Array-排除的字段列表
prettyBooleanfalse是否格式化 JSON 输出

请求体参数(使用 POST 时) #

参数类型是否必填默认值描述
queryObject-Elasticsearch 查询 DSL
fromInteger0起始偏移量
sizeInteger10返回文档数量
sortArray-排序条件
_sourceObject/Array-字段包含/排除配置
track_total_hitsBooleantrue是否跟踪总命中数

请求示例 #

列出所有规则库 #

GET .match_rules/_search

仅获取已编译的规则库 #

GET .match_rules/_search
{
  "query": {
    "term": {
      "status": "compiled"
    }
  }
}

按标签过滤 #

GET .match_rules/_search
{
  "query": {
    "term": {
      "tags": "security"
    }
  }
}

排除规则内容(仅获取元数据) #

GET .match_rules/_search?_source_excludes=rules

分页查询 #

GET .match_rules/_search
{
  "from": 0,
  "size": 20,
  "sort": [
    {"updated": "desc"}
  ]
}

响应示例 #

{
  "took": 5,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": 1.0,
    "hits": [
      {
        "_index": ".match_rules",
        "_id": "security_v1",
        "_version": 2,
        "_score": 1.0,
        "_source": {
          "name": "安全规则库",
          "description": "用于安全事件分类的规则库",
          "tags": ["security", "content-filter"],
          "version": "2",
          "status": "compiled",
          "total_rules": 3,
          "compiled_at": "2026-01-07T08:00:00Z",
          "compiled_nodes": ["node-1", "node-2"],
          "created": "2025-12-31T10:00:00Z",
          "updated": "2025-12-31T10:15:00Z"
        }
      },
      {
        "_index": ".match_rules",
        "_id": "opinion_check",
        "_version": 1,
        "_score": 1.0,
        "_source": {
          "name": "舆情监控规则",
          "description": "用于舆情监控的规则库",
          "tags": ["opinion", "monitoring"],
          "version": "1",
          "status": "pending",
          "total_rules": 5,
          "created": "2025-12-31T10:15:00Z",
          "updated": "2025-12-31T10:15:00Z"
        }
      }
    ]
  }
}

响应字段说明 #

顶层字段 #

字段类型描述
tookInteger查询耗时(毫秒)
timed_outBoolean是否超时
_shardsObject分片信息
hitsObject命中结果

hits 对象 #

字段类型描述
total.valueInteger总命中数
total.relationString总数关系(eq 精确、gte 大于等于)
max_scoreFloat最高得分
hitsArray文档数组

文档 _source 字段 #

字段类型描述
nameString规则库名称
descriptionString规则库描述
tagsString[]分类标签
versionString版本号
statusString编译状态:pendingcompiledpartialfailed
total_rulesInteger规则总数
compiled_atString编译时间戳
compiled_nodesString[]编译节点列表
fieldsString[]声明的数值字段
compositeString[]复合索引定义
createdString创建时间戳
updatedString更新时间戳
error_messageString编译失败时的错误信息

编译状态说明 #

状态描述
pending待编译,规则库已导入但尚未编译
compiled已编译,规则库已成功编译到所有目标节点
partial部分编译,规则库仅编译到部分节点
failed编译失败,规则库编译过程中出现错误

使用建议 #

  1. 排除大字段:使用 _source_excludes=rules 排除规则内容,减少响应大小
  2. 分页浏览:使用 fromsize 参数进行分页
  3. 状态过滤:使用查询 DSL 按状态过滤规则库
  4. 系统索引.match_rules 是系统索引,需要相应权限访问