版本: 6.8-8.9
简而言之,当 Elasticsearch 由于语法不正确或 JSON 格式无效而无法解析内联模板时,就会出现此错误。这可能是由于缺少或多余的逗号、括号或引号造成的。要解决此问题,您应该仔细检查内联模板以确保其格式正确。使用 JSON 验证器来检查任何语法错误。此外,确保模板中使用的所有变量都正确定义和格式化。
日志上下文 #
日志 “Could not parse inline template” 的类名是 SearchTemplateRequest.java。 我们从 Elasticsearch 源代码中提取了以下内容,供那些需要深入了解上下文的人参考:
if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
// convert the template to json which is the only supported XContentType (see CustomMustacheFactory#createEncoder)
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
request.setScript(Strings.toString(builder.copyCurrentStructure(parser)));
} catch (IOException e) {
throw new ParsingException(parser.getTokenLocation(), "Could not parse inline template", e);
}
} else {
request.setScript(parser.text());
}
}; SOURCE_FIELD; ObjectParser.ValueType.OBJECT_OR_STRING);





