{"record":{"id":"e340d4fa5885cc5a","repo":"elastic/elasticsearch","slug":"no-encoder-found-for-media-type","errorCode":null,"errorMessage":"No encoder found for media type [{}]","messagePattern":"No encoder found for media type \\[(.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/CustomMustacheFactory.java","lineNumber":106,"sourceCode":"    private CustomMustacheFactory(String mediaType, boolean detectMissingParams) {\n        super(resourceName -> null); // we do not resolve templates via files or the classpath, etc.\n        setObjectHandler(new CustomReflectionObjectHandler(detectMissingParams));\n        this.encoder = createEncoder(mediaType);\n    }\n\n    @Override\n    public void encode(String value, Writer writer) {\n        try {\n            encoder.encode(value, writer);\n        } catch (IOException e) {\n            throw new MustacheException(\"Unable to encode value\", e);\n        }\n    }\n\n    static Encoder createEncoder(String mediaType) {\n        final Supplier<Encoder> supplier = ENCODERS.get(mediaType);\n        if (supplier == null) {\n            throw new IllegalArgumentException(\"No encoder found for media type [\" + mediaType + \"]\");\n        }\n        return supplier.get();\n    }\n\n    @Override\n    public MustacheVisitor createMustacheVisitor() {\n        return new CustomMustacheVisitor(this);\n    }\n\n    public static Builder builder() {\n        return new Builder();\n    }\n\n    private static class CustomMustacheVisitor extends DefaultMustacheVisitor {\n\n        CustomMustacheVisitor(DefaultMustacheFactory df) {\n            super(df);\n        }","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/CustomMustacheFactory.java#L88-L124","documentation":"Thrown by CustomMustacheFactory.createEncoder() when the requested media type (content type) is not in the ENCODERS map. The factory supports exactly five media types: 'application/json; charset=UTF-8', 'application/json;charset=utf-8', 'application/json', 'text/plain', and 'application/x-www-form-urlencoded'. Any other value passed via the content_type script option triggers this exception.","triggerScenarios":"Executing a search template with the 'content_type' option set to an unsupported value. For example: {\"source\": {...}, \"params\": {...}} with script options specifying a content type like 'application/xml' or 'text/csv'. The option is read from Script.CONTENT_TYPE_OPTION in MustacheScriptEngine.createMustacheFactory() and passed to the builder.","commonSituations":"Passing a custom or wrong MIME type in the content_type option. Using 'application/xml' or 'application/yaml' which are not supported. Typing the content type incorrectly (e.g., 'application/jason'). Copying a content type from a different API that supports more formats.","solutions":["Use one of the five supported content types: 'application/json', 'application/json; charset=UTF-8', 'application/json;charset=utf-8', 'text/plain', or 'application/x-www-form-urlencoded'","If you don't need a specific content type, omit the content_type option entirely — it defaults to 'application/json'","For URL-encoded query parameter output, use 'application/x-www-form-urlencoded'","For plain text passthrough without JSON escaping, use 'text/plain'"],"exampleFix":"// before — search template request with unsupported content type:\nPOST /_search/template\n{\n  \"source\": { \"query\": { \"match\": { \"title\": \"{{q}}\" } } },\n  \"params\": { \"q\": \"test\" },\n  \"content_type\": \"application/xml\"\n}\n\n// after — use a supported content type or omit it:\nPOST /_search/template\n{\n  \"source\": { \"query\": { \"match\": { \"title\": \"{{q}}\" } } },\n  \"params\": { \"q\": \"test\" },\n  \"content_type\": \"text/plain\"\n}","handlingStrategy":"validation","validationCode":"// Validate content_type before submitting search template\nSet<String> VALID_CONTENT_TYPES = Set.of(\n    \"application/json\",\n    \"application/json; charset=UTF-8\",\n    \"application/json;charset=utf-8\",\n    \"text/plain\",\n    \"application/x-www-form-urlencoded\"\n);\nif (contentType != null && !VALID_CONTENT_TYPES.contains(contentType)) {\n    throw new IllegalArgumentException(\"Unsupported content type: \" + contentType);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default content type is application/json — omit the option if unsure","Keep the five valid content types in a shared constant","Document the supported content types in your client library"],"tags":["elasticsearch","lang-mustache","content-type","configuration","template"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}