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

  1. This error should not occur in normal use — report it as a bug if encountered
  2. Ensure you are using a supported join syntax: {{#join delimiter=','}}items{{/join}}
  3. Check for version mismatches if running a patched or custom build of Elasticsearch
  4. 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

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


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/e4e5490188655d58. Report an issue: GitHub.