适用版本: 6.8-8.x
1. 错误异常的基本描述 #
could not parse [http] input for watch [<id>]. missing require [request] field 是 Elasticsearch Watcher 在解析 HTTP input 配置时抛出的解析异常。该错误表示 Watcher 在解析 input.http 配置段时,发现缺少必填的 request 字段,因此无法构造真正要发出的 HTTP 请求,导致 watch 无法被正常创建或执行。
需要注意的是,源码字符串中写的是 missing require 而非 missing required,这是 Elasticsearch 源码中的原始措辞,不影响语义理解。
常见现象 #
- 调用 Watcher API(如
_watcher/watch/<id>/_execute或 PUT_watcher/watch/<id>)时返回400 Bad Request。 - 响应体中包含
could not parse [http] input for watch和missing require [request] field关键字。 - Kibana 的 Watcher 管理界面可能无法保存或执行该 watch,并在界面上显示解析错误提示。
- 如果 watch 已存在但配置损坏,后续触发时可能直接跳过执行或记录执行失败。
典型报错与异常栈 #
{
"error": {
"root_cause": [
{
"type": "parse_exception",
"reason": "could not parse [http] input for watch [my-watch]. missing require [request] field"
}
],
"type": "parse_exception",
"reason": "could not parse [http] input for watch [my-watch]. missing require [request] field"
},
"status": 400
}
服务端日志中可能出现类似以下堆栈:
ElasticsearchParseException: could not parse [http] input for watch [my-watch]. missing require [request] field
at org.elasticsearch.xpack.watcher.input.http.HttpInput$Parser.parse(HttpInput.java:...)
at org.elasticsearch.xpack.watcher.input.InputRegistry.parse(InputRegistry.java:...)
2. 为什么会发生这个错误 #
http input 的核心作用是让 Watcher 定期向外部服务发起 HTTP 请求,并将响应结果作为 watch 执行上下文的一部分。request 字段正是描述"向哪里发请求、怎么发请求"的核心配置段,缺少它 Watcher 就无法工作。
常见原因通常包括:
- 完全遗漏
request字段:在input.http下只写了extract、timeout、connection_timeout等辅助字段,忘记添加request。 request字段位置错误:误将request写到了input根层级或其他错误位置,而不是input.http的直接子字段。- Mustache 模板渲染导致字段丢失:当 watch 中使用了动态模板,且模板条件分支在某些场景下把
request整段裁掉,导致渲染后的最终配置中request不存在。 - JSON 结构层级错误:误将
request嵌套在http以外的其他对象中,或将其写成了数组而非对象。 - 从旧版本配置迁移时遗漏:不同版本的 Watcher 配置格式略有差异,迁移时可能遗漏关键字段。
3. 如何排查和解决这个异常和解决这个异常 #
建议按以下步骤排查:
- 检查 watch 的完整配置:通过
GET _watcher/watch/<id>获取当前 watch 定义,重点检查input.http下是否存在request字段。 - 确认
request字段的数据类型:request必须是对象(object),不能是字符串、数组或null。检查是否有模板渲染导致其类型异常。 - 检查 Mustache 模板逻辑:如果 watch 中使用了
{{#condition}}...{{/condition}}等模板语法,确认在所有分支下request都能被正确渲染。 - 验证 JSON 结构层级:对照官方文档确认
request是否位于input→http→request的正确路径上。 - 使用
_executeAPI 测试:通过POST _watcher/watch/<id>/_execute手动触发执行,观察详细错误信息。
排查时需要注意的问题 #
- 不要只看客户端返回的错误摘要,必须查看完整的响应体和 Elasticsearch 服务端日志,确认错误发生在解析阶段还是执行阶段。
- 如果 watch 配置中使用了模板,建议在排查时先展开模板,确认渲染后的最终配置结构是否正确。
- Watcher 的配置错误有时会被静默忽略,建议在修改后主动执行一次
_execute验证。
4. 如何解决这个错误 #
正确的配置结构 #
一个完整的 http input 配置必须包含 request 字段,其基本结构如下:
{
"trigger": {
"schedule": {
"interval": "10m"
}
},
"input": {
"http": {
"request": {
"scheme": "https",
"host": "example.org",
"port": 443,
"method": "get",
"path": "/api/health"
},
"extract": ["status", "message"]
}
},
"condition": {
"compare": {
"ctx.payload.status": {
"eq": "ok"
}
}
}
}
错误示例与修正对比 #
错误示例 1:request 完全缺失
{
"input": {
"http": {
"extract": ["hits.total"]
}
}
}
修正后:
{
"input": {
"http": {
"request": {
"scheme": "https",
"host": "example.org",
"port": 443,
"path": "/api/search"
},
"extract": ["hits.total"]
}
}
}
错误示例 2:request 位置错误
{
"input": {
"http": {},
"request": {
"scheme": "https",
"host": "example.org"
}
}
}
错误示例 3:request 类型错误(写成了数组)
{
"input": {
"http": {
"request": []
}
}
}
request 字段支持的完整参数
#
| 参数 | 必填 | 说明 |
|---|---|---|
scheme | 否 | 协议,可选 http 或 https,默认 http |
host | 是 | 目标主机名或 IP 地址 |
port | 否 | 目标端口,默认 80(http)或 443(https) |
path | 否 | 请求路径,以 / 开头 |
method | 否 | HTTP 方法,如 get、post、put 等,默认 get |
headers | 否 | 自定义请求头对象 |
body | 否 | 请求体(用于 POST/PUT 等) |
auth | 否 | 认证配置,支持 basic 认证 |
proxy | 否 | 代理服务器配置 |
connection_timeout | 否 | 连接超时,默认 10s |
read_timeout | 否 | 读取超时,默认 10s |
url | 否 | 完整 URL(与 scheme+host+port+path 二选一) |
后续注意事项与推荐建议 #
- 在创建或修改 watch 后,务必通过
_watcher/watch/<id>/_execute接口验证配置是否正确。 - 对于复杂的 watch 配置,建议先在开发环境验证,再同步到生产环境。
- 使用 Kibana 的 Watcher UI 可以帮助可视化配置结构,减少层级错误。
借助 INFINI 产品提升排障效率 #
- INFINI Console 适合查看集群健康度、索引状态、错误趋势和请求画像,帮助快速判断 watch 执行失败的影响范围。
- INFINI Gateway 适合部署在 Elasticsearch 前面做请求观测、限流和流量治理,可以帮助捕获 Watcher 发出的 HTTP 请求,便于调试外部接口调用问题。
5. 小结 #
could not parse [http] input for watch ... missing require [request] field 的根因就是 input.http 下缺少必填的 request 字段。修复时只需确保 request 字段存在于正确位置、类型正确且包含必要的请求信息(至少包含 host)。同时建议检查 Mustache 模板渲染结果,避免动态配置在某些分支下丢失关键字段。养成良好的 watch 配置验证习惯,可以大幅减少此类问题的发生。
相关错误 #
附:日志上下文 #
下面保留当前页面中的源码或日志片段,便于继续结合异常调用栈定位问题:
token);
}
} if (request == null) {
throw new ElasticsearchParseException("could not parse [{}] input for watch [{}]. missing require [{}] field", TYPE, watchId,
Field.REQUEST.getPreferredName());
} if (expectedResponseBodyType == HttpContentType.TEXT && extract != null ) {
throw new ElasticsearchParseException("could not parse [{}] input for watch [{}]. key extraction is not supported for content" +





