elastic/elasticsearch · error · MustacheException
Failed to extract delimiter for join function
Error message
Failed to extract delimiter for join function
What it means
Thrown by CustomJoinerCode.extractDelimiter() when the join function's variable string does not match the expected pattern '^join delimiter=\'(.*)\'$'. This is a defensive guard: in normal flow, CustomJoinerCode.match() (which uses the same PATTERN with matches()) is checked before the constructor is invoked, so if match() returns true, extractDelimiter should always succeed. This error is essentially unreachable through the standard template compilation path.
Source
Thrown at modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/CustomMustacheFactory.java:309
static boolean match(String variable) {
return CODE.equalsIgnoreCase(variable);
}
}
private static class CustomJoinerCode extends JoinerCode {
private static final Pattern PATTERN = Pattern.compile("^" + CODE + " delimiter='(.*)'$");
CustomJoinerCode(TemplateContext tc, DefaultMustacheFactory df, Mustache mustache, String variable) {
super(tc, df, mustache, extractDelimiter(variable));
}
private static String extractDelimiter(String variable) {
Matcher matcher = PATTERN.matcher(variable);
if (matcher.find()) {
return matcher.group(1);
}
throw new MustacheException("Failed to extract delimiter for join function");
}
static boolean match(String variable) {
return PATTERN.matcher(variable).matches();
}
}
/**
* This function encodes a string using the {@link URLEncoder#encode(String, String)} method
* with the UTF-8 charset.
*/
private static class UrlEncoderCode extends DefaultMustache {
private static final String CODE = "url";
private final Encoder encoder;
UrlEncoderCode(TemplateContext tc, DefaultMustacheFactory df, Mustache mustache, String variable) {
super(tc, df, mustache.getCodes(), variable);View on GitHub (pinned to db6a809a66)
Solutions
- This error should not occur in normal use — report it as a bug if encountered
- Ensure you are using a supported join syntax: {{#join delimiter=','}}items{{/join}}
- Check for version mismatches if running a patched or custom build of Elasticsearch
- Use the simpler {{#join}}items{{/join}} (comma-delimited default) as a workaround
Example fix
// standard join syntax (should not trigger this error):
{{#join delimiter='|'}}tags{{/join}} Defensive patterns
Strategy: validation
Validate before calling
// Validate join delimiter syntax before submission
Pattern JOIN_PATTERN = Pattern.compile("^join delimiter='(.*)'$");
if (!JOIN_PATTERN.matcher(variable).matches()) {
// use simple {{#join}}var{{/join}} instead
} Prevention
- Use the standard join delimiter syntax: {{#join delimiter='|'}}items{{/join}}
- This error should not occur in normal use — report as bug if seen
- Falls back to comma-delimited {{#join}}items{{/join}} if delimiter syntax is problematic
When it happens
Trigger: Theoretically triggered if CustomJoinerCode is constructed directly with a variable string that doesn't match the pattern. Through normal template compilation, the iterable() visitor method calls CustomJoinerCode.match(variable) first, so only matching variables reach the constructor. This path would only fire if internal code is modified to bypass the match() check.
Common situations: Not normally encountered by users. Could surface if a code change introduces a discrepancy between the match() predicate and the extractDelimiter() parsing logic, or if the PATTERN regex is modified inconsistently. If you see this error, it likely indicates a bug in the lang-mustache module.
Related errors
- Mustache function [{}] must contain one and only one identif
- Exception while parsing mustache function [{}] at line {}
- Unable to encode value
- No encoder found for media type [{}]
- Cannot expand '%s' because partial templates are not support
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/e4e5490188655d58.
Report an issue: GitHub.