{"record":{"id":"60a7e3106b130bc8","repo":"NationalSecurityAgency/ghidra","slug":"gettype-scripts-cannot-be-used-for-context-co","errorCode":null,"errorMessage":"{getType()}scripts cannot be used for context [{context.name}]","messagePattern":"(.+?)scripts cannot be used for context \\[(.+?)\\]","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Extensions/BSimElasticPlugin/src/org/elasticsearch/plugin/analysis/lsh/BSimScriptEngine.java","lineNumber":29,"sourceCode":" * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage org.elasticsearch.plugin.analysis.lsh;\n\nimport java.util.*;\n\nimport org.elasticsearch.script.*;\n\npublic class BSimScriptEngine implements ScriptEngine {\n\tprivate final static String ENGINE_NAME = \"bsim_scripts\";\n\n\t@Override\n\tpublic <FactoryType> FactoryType compile(String scriptName, String scriptSource,\n\t\t\tScriptContext<FactoryType> context, Map<String, String> params) {\n\t\tif (context.equals(ScoreScript.CONTEXT) == false) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\tgetType() + \"scripts cannot be used for context [\" + context.name + \"]\");\n\t\t}\n\t\tif (VectorCompareScriptFactory.SCRIPT_NAME.equals(scriptSource)) {\n\t\t\tScoreScript.Factory factory = new VectorCompareScriptFactory();\n\t\t\treturn context.factoryClazz.cast(factory);\n\t\t}\n\t\tthrow new IllegalArgumentException(\"Unknown script name \" + scriptSource);\n\t}\n\n\t@Override\n\tpublic void close() {\n\t\t// Can free up resources\n\t}\n\n\t@Override\n\tpublic Set<ScriptContext<?>> getSupportedContexts() {\n\t\treturn Collections.singleton(ScoreScript.CONTEXT);\n\t}","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Extensions/BSimElasticPlugin/src/org/elasticsearch/plugin/analysis/lsh/BSimScriptEngine.java#L11-L47","documentation":"BSimScriptEngine is an Elasticsearch ScriptEngine that supports only the ScoreScript.CONTEXT (per-document scoring). compile checks the requested ScriptContext and rejects anything else with IllegalArgumentException, because BSim's vector-comparison logic only makes sense during scoring. getSupportedContexts confirms this by advertising just ScoreScript.CONTEXT.","triggerScenarios":"Compiling/registering a BSim script under a non-Score context - e.g. an aggregation, ingest, or update context, or a query that dispatches the script to the wrong context.","commonSituations":"A search query hitting the wrong script context; a misconfigured scripted query; an Elasticsearch version change that routes the script through a different context; using the BSim script outside a score-script query.","solutions":["Use the BSim script only within a score-script query (ScoreScript.CONTEXT).","Verify getSupportedContexts() returns ScoreScript.CONTEXT and your query type uses that context.","If you need non-scoring behavior, write a separate ScriptEngine for that context rather than reusing BSim's."],"exampleFix":"// before: script compiled into an aggregation context -> throws\n// after: issue the script via a score-script query (ScoreScript.CONTEXT)\nScriptScoreQueryBuilder q = ScriptScoreQuery.builder()\n    .query(matchAllQuery())\n    .script(new Script(ScriptType.INDEXED, \"bsim_scripts\", VectorCompareScriptFactory.SCRIPT_NAME, params))\n    .build();","handlingStrategy":"validation","validationCode":"// Only compile for the supported context:\nif (!ScoreScript.CONTEXT.equals(requestedContext)) {\n    throw new IllegalArgumentException(\"BSim scripts require ScoreScript.CONTEXT\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use BSim scripts only inside score-script queries.","Cross-check getSupportedContexts() before dispatching a script."],"tags":["elasticsearch","bsim","scripting","query"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}