{"record":{"id":"1c98971cd7d9fb53","repo":"elastic/elasticsearch","slug":"cannot-expand-s-because-partial-templates-are-n","errorCode":null,"errorMessage":"Cannot expand '%s' because partial templates are not supported","messagePattern":"Cannot expand '(.+?)' because partial templates are not supported","errorType":"exception","errorClass":"MustacheException","httpStatus":null,"severity":"error","filePath":"modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/CustomMustacheFactory.java","lineNumber":145,"sourceCode":"        public void iterable(TemplateContext templateContext, String variable, Mustache mustache) {\n            if (ToJsonCode.match(variable)) {\n                list.add(new ToJsonCode(templateContext, df, mustache, variable));\n            } else if (JoinerCode.match(variable)) {\n                list.add(new JoinerCode(templateContext, df, mustache));\n            } else if (CustomJoinerCode.match(variable)) {\n                list.add(new CustomJoinerCode(templateContext, df, mustache, variable));\n            } else if (UrlEncoderCode.match(variable)) {\n                list.add(new UrlEncoderCode(templateContext, df, mustache, variable));\n            } else {\n                list.add(new IterableCode(templateContext, df, mustache, variable));\n            }\n        }\n\n        @Override\n        public void partial(TemplateContext tc, String variable, String indent) {\n            // throwing a mustache exception here is important because this gets caught, handled (closing readers, etc.),\n            // and re-thrown in the mustache parser itself\n            throw new MustacheException(Strings.format(\"Cannot expand '%s' because partial templates are not supported\", variable));\n        }\n\n        @Override\n        public void dynamicPartial(TemplateContext tc, final String variable, String indent) {\n            // throwing a mustache exception here is important because this gets caught, handled (closing readers, etc.),\n            // and re-thrown in the mustache parser itself\n            throw new MustacheException(Strings.format(\"Cannot expand '%s' because dynamic partial templates are not supported\", variable));\n        }\n    }\n\n    /**\n     * Base class for custom Mustache functions\n     */\n    private abstract static class CustomCode extends IterableCode {\n\n        private final String code;\n\n        CustomCode(TemplateContext tc, DefaultMustacheFactory df, Mustache mustache, String code) {","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/CustomMustacheFactory.java#L127-L163","documentation":"Thrown by CustomMustacheVisitor.partial() when a Mustache template uses the partial template syntax ({{> name}} or {{>\"name\"}}). Elasticsearch's mustache implementation deliberately does not support partial templates because templates are provided as inline strings, not resolved from files or classpath. The factory constructor passes resourceName -> null to DefaultMustacheFactory to prevent file-based resolution.","triggerScenarios":"Including a partial template reference in a search template. For example, a template source containing {{> header}} or {{> \"shared_clause\"}}. The mustache parser invokes the visitor's partial() method during compilation, which immediately throws.","commonSituations":"Porting a mustache template from another system (like a web framework) that relies on partials for modularity. Attempting to share template fragments across multiple search templates via partial includes. Copying mustache syntax examples from generic mustache documentation.","solutions":["Remove all {{> ...}} partial references from the template — Elasticsearch does not support them","Inline any shared content directly into the template body","If you need reusable template fragments, store them client-side and concatenate before sending to Elasticsearch","Use stored scripts (PUT /_scripts/<id>) to save and reference entire templates, but note that partial inclusion between stored scripts is still not supported"],"exampleFix":"// before — template source with partial:\n{\"query\": {\"bool\": {\"must\": [{{> filter_clause}}]}}}\n\n// after — inline the partial content:\n{\"query\": {\"bool\": {\"must\": [{\"term\": {\"status\": \"{{status}}\"}}]}}}","handlingStrategy":"validation","validationCode":"// Validate template source for partial syntax before submission\nString templateSource = \"...\";\nif (templateSource.contains(\"{{>\") || templateSource.contains(\"{{>\")) {\n    throw new IllegalArgumentException(\"Partial templates ({{> ...}}) are not supported in Elasticsearch\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never use {{> name}} partial syntax in Elasticsearch templates","Inline all shared content directly","Store reusable full templates via PUT /_scripts/<id>"],"tags":["elasticsearch","lang-mustache","partial","template","unsupported-feature"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}