--- title: "查询规则库列表" date: 2026-01-16 lastmod: 2026-01-16 description: "获取所有规则库的列表" tags: ["规则库", "查询", "列表"] summary: "获取系统中所有规则库(规则仓库)的列表和概要信息。 API 格式 # GET .match_rules/_search POST .match_rules/_search API 作用 # 该 API 用于列出所有可用的规则库,支持: 查看所有规则库 按状态、标签等条件过滤 分页浏览规则库 获取规则库的元数据信息 API 参数 # 查询参数 # 参数 类型 是否必填 默认值 描述 q String 否 - 全文搜索查询 from Integer 否 0 分页起始偏移量 size Integer 否 10 每页返回的文档数量 sort String 否 - 排序字段和方式 _source String/Array 否 所有字段 返回的字段列表 _source_excludes String/Array 否 - 排除的字段列表 pretty Boolean 否 false 是否格式化 JSON 输出 请求体参数(使用 POST 时) # 参数 类型 是否必填 默认值 描述 query Object 否 - Elasticsearch 查询 DSL from Integer 否 0 起始偏移量 size Integer 否 10 返回文档数量 sort Array 否 - 排序条件 _source Object/Array 否 - 字段包含/排除配置 track_total_hits Boolean 否 true 是否跟踪总命中数 请求示例 # 列出所有规则库 # GET ." --- 获取系统中所有规则库(规则仓库)的列表和概要信息。 ## API 格式 ``` GET .match_rules/_search POST .match_rules/_search ``` ## API 作用 该 API 用于列出所有可用的规则库,支持: - 查看所有规则库 - 按状态、标签等条件过滤 - 分页浏览规则库 - 获取规则库的元数据信息 ## API 参数 ### 查询参数 | 参数 | 类型 | 是否必填 | 默认值 | 描述 | |------|------|----------|--------|------| | `q` | String | 否 | - | 全文搜索查询 | | `from` | Integer | 否 | `0` | 分页起始偏移量 | | `size` | Integer | 否 | `10` | 每页返回的文档数量 | | `sort` | String | 否 | - | 排序字段和方式 | | `_source` | String/Array | 否 | 所有字段 | 返回的字段列表 | | `_source_excludes` | String/Array | 否 | - | 排除的字段列表 | | `pretty` | Boolean | 否 | `false` | 是否格式化 JSON 输出 | ### 请求体参数(使用 POST 时) | 参数 | 类型 | 是否必填 | 默认值 | 描述 | |------|------|----------|--------|------| | `query` | Object | 否 | - | Elasticsearch 查询 DSL | | `from` | Integer | 否 | `0` | 起始偏移量 | | `size` | Integer | 否 | `10` | 返回文档数量 | | `sort` | Array | 否 | - | 排序条件 | | `_source` | Object/Array | 否 | - | 字段包含/排除配置 | | `track_total_hits` | Boolean | 否 | `true` | 是否跟踪总命中数 | ## 请求示例 ### 列出所有规则库 ``` 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"} ] } ``` ## 响应示例 ```json { "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" } } ] } } ``` ## 响应字段说明 ### 顶层字段 | 字段 | 类型 | 描述 | |------|------|------| | `took` | Integer | 查询耗时(毫秒) | | `timed_out` | Boolean | 是否超时 | | `_shards` | Object | 分片信息 | | `hits` | Object | 命中结果 | ### hits 对象 | 字段 | 类型 | 描述 | |------|------|------| | `total.value` | Integer | 总命中数 | | `total.relation` | String | 总数关系(`eq` 精确、`gte` 大于等于) | | `max_score` | Float | 最高得分 | | `hits` | Array | 文档数组 | ### 文档 _source 字段 | 字段 | 类型 | 描述 | |------|------|------| | `name` | String | 规则库名称 | | `description` | String | 规则库描述 | | `tags` | String[] | 分类标签 | | `version` | String | 版本号 | | `status` | String | 编译状态:`pending`、`compiled`、`partial`、`failed` | | `total_rules` | Integer | 规则总数 | | `compiled_at` | String | 编译时间戳 | | `compiled_nodes` | String[] | 编译节点列表 | | `fields` | String[] | 声明的数值字段 | | `composite` | String[] | 复合索引定义 | | `created` | String | 创建时间戳 | | `updated` | String | 更新时间戳 | | `error_message` | String | 编译失败时的错误信息 | ## 编译状态说明 | 状态 | 描述 | |------|------| | `pending` | 待编译,规则库已导入但尚未编译 | | `compiled` | 已编译,规则库已成功编译到所有目标节点 | | `partial` | 部分编译,规则库仅编译到部分节点 | | `failed` | 编译失败,规则库编译过程中出现错误 | ## 使用建议 1. **排除大字段**:使用 `_source_excludes=rules` 排除规则内容,减少响应大小 2. **分页浏览**:使用 `from` 和 `size` 参数进行分页 3. **状态过滤**:使用查询 DSL 按状态过滤规则库 4. **系统索引**:`.match_rules` 是系统索引,需要相应权限访问