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

适用版本: 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 watchmissing 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 下只写了 extracttimeoutconnection_timeout 等辅助字段,忘记添加 request
  • request 字段位置错误:误将 request 写到了 input 根层级或其他错误位置,而不是 input.http 的直接子字段。
  • Mustache 模板渲染导致字段丢失:当 watch 中使用了动态模板,且模板条件分支在某些场景下把 request 整段裁掉,导致渲染后的最终配置中 request 不存在。
  • JSON 结构层级错误:误将 request 嵌套在 http 以外的其他对象中,或将其写成了数组而非对象。
  • 从旧版本配置迁移时遗漏:不同版本的 Watcher 配置格式略有差异,迁移时可能遗漏关键字段。

3. 如何排查和解决这个异常和解决这个异常 #

建议按以下步骤排查:

  1. 检查 watch 的完整配置:通过 GET _watcher/watch/<id> 获取当前 watch 定义,重点检查 input.http 下是否存在 request 字段。
  2. 确认 request 字段的数据类型request 必须是对象(object),不能是字符串、数组或 null。检查是否有模板渲染导致其类型异常。
  3. 检查 Mustache 模板逻辑:如果 watch 中使用了 {{#condition}}...{{/condition}} 等模板语法,确认在所有分支下 request 都能被正确渲染。
  4. 验证 JSON 结构层级:对照官方文档确认 request 是否位于 inputhttprequest 的正确路径上。
  5. 使用 _execute API 测试:通过 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协议,可选 httphttps,默认 http
host目标主机名或 IP 地址
port目标端口,默认 80(http)或 443(https
path请求路径,以 / 开头
methodHTTP 方法,如 getpostput 等,默认 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" +