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

版本: 6.8-8.9

简而言之,当发起 Elasticsearch 请求时缺少必需的请求体,就会出现此错误。这通常发生在尝试执行需要额外信息的操作时,例如创建或更新文档。要解决此问题,请确保您的请求包含有效的 JSON 主体,其中包含所有必要的信息。如果您使用工具或库来发起请求,请查看其文档以确保正确使用。此外,请确保将请求的内容类型设置为 ‘application/json’。

日志上下文 #

日志 “request body is required” 的类名是 RestRequest.java. 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入了解上下文的人参考:

/**
 * @return content of the request body or throw an exception if the body or content type is missing
 */
 public final BytesReference requiredContent() {
 if (hasContent() == false) {
 throw new ElasticsearchParseException("request body is required");
 } else if (xContentType.get() == null) {
 throw new IllegalStateException("unknown content type");
 }
 return content();
 }