Fix UpdateQuery.Builder to allow only a scriptname to be set.

Signed-off-by: Peter-Josef Meisch <pj.meisch@sothawo.com>
This commit is contained in:
Peter-Josef Meisch 2025-12-04 23:24:35 +01:00 committed by GitHub
parent e31b66768b
commit 69746441e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 2 deletions

View File

@ -438,8 +438,8 @@ public class UpdateQuery {
public UpdateQuery build() { public UpdateQuery build() {
if (script == null && document == null && query == null) { if (script == null && scriptName == null && document == null && query == null) {
throw new IllegalArgumentException("either script, document or query must be set"); throw new IllegalArgumentException("either script, scriptName, document or query must be set");
} }
return new UpdateQuery(id, script, params, document, upsert, lang, routing, scriptedUpsert, docAsUpsert, return new UpdateQuery(id, script, params, document, upsert, lang, routing, scriptedUpsert, docAsUpsert,

View File

@ -0,0 +1,45 @@
package org.springframework.data.elasticsearch.core.query;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.data.elasticsearch.core.document.Document;
class UpdateQueryTest {
@Test // #3205
@DisplayName("should build query with only a script")
void shouldBuildQueryWithOnlyAScript() {
UpdateQuery.builder("id")
.withScript("script")
.build();
}
@Test // #3205
@DisplayName("should build query with only a scriptname")
void shouldBuildQueryWithOnlyAScriptName() {
UpdateQuery.builder("id")
.withScriptName("scriptname")
.build();
}
@Test // #3205
@DisplayName("should build query with only a document")
void shouldBuildQueryWithOnlyASDocument() {
UpdateQuery.builder("id")
.withDocument(Document.create())
.build();
}
@Test // #3205
@DisplayName("should build query with only a query")
void shouldBuildQueryWithOnlyAQuery() {
Query query = StringQuery.builder("StrignQuery").build();
UpdateQuery.builder(query)
.build();
}
}