{"record":{"id":"e578839fbe984e25","repo":"elastic/elasticsearch","slug":"unsupported-script-context-name","errorCode":null,"errorMessage":"unsupported script context name [{}]","messagePattern":"unsupported script context name \\[(.+?)\\]","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java","lineNumber":164,"sourceCode":"        }\n\n        private static Map<String, ScriptContext<?>> getSupportedContexts() {\n            Map<String, ScriptContext<?>> contexts = new HashMap<>();\n            contexts.put(PainlessTestScript.CONTEXT.name, PainlessTestScript.CONTEXT);\n            contexts.put(FilterScript.CONTEXT.name, FilterScript.CONTEXT);\n            contexts.put(ScoreScript.CONTEXT.name, ScoreScript.CONTEXT);\n            for (ScriptContext<?> runtimeFieldsContext : ScriptModule.RUNTIME_FIELDS_CONTEXTS) {\n                contexts.put(runtimeFieldsContext.name, runtimeFieldsContext);\n            }\n            return Collections.unmodifiableMap(contexts);\n        }\n\n        static final Map<String, ScriptContext<?>> SUPPORTED_CONTEXTS = getSupportedContexts();\n\n        static ScriptContext<?> fromScriptContextName(String name) {\n            ScriptContext<?> scriptContext = SUPPORTED_CONTEXTS.get(name);\n            if (scriptContext == null) {\n                throw new UnsupportedOperationException(\"unsupported script context name [\" + name + \"]\");\n            }\n            return scriptContext;\n        }\n\n        static class ContextSetup implements Writeable, ToXContentObject {\n\n            private static final ParseField INDEX_FIELD = new ParseField(\"index\");\n            private static final ParseField DOCUMENT_FIELD = new ParseField(\"document\");\n            private static final ParseField QUERY_FIELD = new ParseField(\"query\");\n            private static final ConstructingObjectParser<ContextSetup, Void> PARSER = new ConstructingObjectParser<>(\n                \"execute_script_context\",\n                args -> new ContextSetup((String) args[0], (BytesReference) args[1], (QueryBuilder) args[2])\n            );\n\n            static {\n                PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), INDEX_FIELD);\n                PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> {\n                    try (XContentBuilder b = XContentBuilder.builder(p.contentType().xContent())) {","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java#L146-L182","documentation":"PainlessExecuteAction.fromScriptContextName looks up the requested context in the static SUPPORTED_CONTEXTS map (PainlessTestScript, FilterScript, ScoreScript, plus ScriptModule.RUNTIME_FIELDS_CONTEXTS). If the name is absent it throws UnsupportedOperationException — note this is UnsupportedOperationException, not IllegalArgumentException, distinguishing it from error 1350. The name is interpolated.","triggerScenarios":"Calling POST /_scripts/painless/_execute with a 'context' field set to a name not in the execute API's fixed allowlist — e.g. an ingest or update context name, or a custom plugin context, none of which are supported by the standalone _execute endpoint.","commonSituations":"Trying to test an ingest-style script via the _execute API; using a context name valid elsewhere (aggregation, update) but unsupported here; version differences in runtime-field context names.","solutions":["Use one of the supported execute contexts: 'painless_test', 'filter', 'score', or a runtime-field context name.","For other contexts, test the script through its native endpoint (e.g. _ingest/pipeline/_simulate, _update_by_query) instead of _execute.","List valid names by inspecting SUPPORTED_CONTEXTS keys or the Painless execute docs for your ES version."],"exampleFix":"// before\nPOST /_scripts/painless/_execute\n{ \"script\": {...}, \"context\": \"ingest\" } // not supported -> 1351\n// after\nPOST /_scripts/painless/_execute\n{ \"script\": {...}, \"context\": \"filter\", \"context_setup\": {...} }","handlingStrategy":"validation","validationCode":"static final Set<String> EXECUTABLE = Set.of(\"painless_test\", \"filter\", \"score\");\nvoid assertExecutableContext(String name) {\n    if (!EXECUTABLE.contains(name) && !name.startsWith(\"bool_field\") && !name.endsWith(\"_field\"))\n        throw new UnsupportedOperationException(\"context not executable via _execute: \" + name);\n}","typeGuard":null,"tryCatchPattern":"try {\n    client.execute(PainlessExecuteAction.INSTANCE, request);\n} catch (UnsupportedOperationException e) {\n    if (e.getMessage().startsWith(\"unsupported script context name\")) {\n        // switch to a native endpoint (_ingest/pipeline/_simulate, _update_by_query) for that context\n    }\n    throw e;\n}","preventionTips":["Remember _execute supports only filter/score/painless_test/runtime-field contexts.","For ingest/update scripts, use _ingest/pipeline/_simulate or _update_by_query instead.","Catch UnsupportedOperationException specifically — this error uses it, not IllegalArgumentException."],"tags":["painless","scripting","rest-api","script-context","elasticsearch"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}