Repository navigation
Description
UpdateQuery.Builder exposes withScriptName(...) and UpdateQuery.Builder.build() accepts it as a valid way to define an update:
if (script == null && scriptName == null && document == null && query == null) {
throw new IllegalArgumentException("either script, scriptName, document or query must be set");
}However, ElasticsearchOperations.update(UpdateQuery, IndexCoordinates) never sends that script. The request reaches Elasticsearch with neither script nor doc, and the server answers:
400 Validation Failed: 1: script or doc is missing
Cause
RequestConverter.documentUpdateRequest (line 1059 in 6.0.5) guards the whole script block on the inline source rather than on the presence of script data:
1066: var scriptData = query.getScriptData();
1067: var script = scriptData != null ? scriptData.script() : null; // inline source only
1068:
1069: if (script != null) { // <-- guard
1076: uqb.script(sb -> {
1077: sb.lang(scriptData.language()).params(params);
1081: if (script != null) { sb.source(s -> s.scriptString(script)); }
1084: sb.id(scriptData.scriptName()); // never reached for a stored script
});
}With withScriptName(...) and no withScript(...), scriptData.script() is null, the block at 1069 is skipped, and sb.id(scriptData.scriptName()) at 1084 is never executed.
The bulk path does not have this problem. RequestConverter.getScript(ScriptData) (around line 735) sets the id unconditionally and only appends the source when present:
sb.lang(scriptData.language()).params(params).id(scriptData.scriptName());
if (scriptData.script() != null) { sb.source(s -> s.scriptString(scriptData.script())); }which is why bulkUpdate(...) and updateByQuery(...) both transmit stored scripts correctly, and only the single-document update does not.
Why the bulk workaround is not always available
Elasticsearch rejects scripted updates sent through _bulk on any index containing a semantic_text field, with 400 Cannot apply update with a script on indices that contain [semantic_text] field(s) (see elastic/elasticsearch#136074) and reference. The single-document _update endpoint is not subject to that restriction, because it resolves the script server-side before the inference filter processes the resulting document.
So for indices with semantic_text, the single-document update is the only path that can carry a script — and it is precisely the path where a stored script is silently dropped. The two restrictions combined leave inline scripts as the sole option, which forces applications to ship the script with the code instead of managing it as a cluster-side artefact.
Suggested fix
Guard on the script data rather than on the inline source, so a stored script is attached as well:
if (scriptData != null && (scriptData.script() != null || scriptData.scriptName() != null)) {
uqb.script(sb -> {
sb.params(params);
if (scriptData.script() != null) {
sb.lang(scriptData.language());
sb.source(s -> s.scriptString(scriptData.script()));
}
else {
sb.id(scriptData.scriptName());
}
return sb;
});
}
Activity
[-]DocumentUpdateRequest silently ignores a stored script (withScriptName) on the single-document update[/-][+]Update fails silently when specifying a stored script (withScriptName)[/+]adityaanikam commentedon Aug 9, 2026
Confirmed exactly against current main: the guard at
documentUpdateRequestisif (script != null), so a stored script only update withscriptData.scriptName()set andscriptData.script()null skips the whole block andsb.id(scriptData.scriptName())never runs. The bulk path you found (getScript) sets.id()unconditionally and only wraps.source()in a null check, so it doesn't have this problem. Fix looks straightforward, guard onscriptData != nullwith either field set, like you suggested. I'd like to open the PR.sothawo commentedon Aug 15, 2026
Thank you for finding and reporting. While having a look at this I found that the
getScript(ScriptData)can be reused, so it's basically replacing the existing codewith just this:
Elasticsearch's query builder
script()method can handlenullvalues, so it's safe to just pass in the result fromgetScript(scriptDate)No need for a PR, I just have the changes on my machine, but I have to wait until after release on Monday as the branches relevant for the releases are locked down in release preparation
Edu93u commentedon Aug 17, 2026
Thank you for your reply and for fixing it.
Fix script handling when building an UpdateQuery.
Fix script handling when building an UpdateQuery.
Fix script handling when building an UpdateQuery.
Fix script handling when building an UpdateQuery.
Fix script handling when building an UpdateQuery.