getMatchedQueries() {
return matchedQueries;
}
diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/ScriptData.java b/src/main/java/org/springframework/data/elasticsearch/core/query/ScriptData.java
index 1a81988cd..fc81b95d4 100644
--- a/src/main/java/org/springframework/data/elasticsearch/core/query/ScriptData.java
+++ b/src/main/java/org/springframework/data/elasticsearch/core/query/ScriptData.java
@@ -15,100 +15,110 @@
*/
package org.springframework.data.elasticsearch.core.query;
-import java.util.Map;
-import java.util.function.Function;
-
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
+import java.util.Map;
+import java.util.function.Function;
+
/**
* value class combining script information.
+ *
+ * A script is either an inline script, then the script parameters must be set
+ * or it refers to a stored script, then the name parameter is required.
*
+ * @param language the language when the script is passed in the script parameter
+ * @param script the script to use as inline script
+ * @param scriptName the name when using a stored script
+ * @param params the script parameters
* @author Peter-Josef Meisch
* @since 4.4
*/
-public record ScriptData(ScriptType type, @Nullable String language, @Nullable String script,
- @Nullable String scriptName, @Nullable Map params) {
-
- public ScriptData(ScriptType type, @Nullable String language, @Nullable String script, @Nullable String scriptName,
- @Nullable Map params) {
-
- Assert.notNull(type, "type must not be null");
-
- this.type = type;
- this.language = language;
- this.script = script;
- this.scriptName = scriptName;
- this.params = params;
- }
-
- /**
- * @since 5.2
- */
- public static ScriptData of(ScriptType type, @Nullable String language, @Nullable String script,
- @Nullable String scriptName, @Nullable Map params) {
- return new ScriptData(type, language, script, scriptName, params);
- }
-
- public static ScriptData of(Function builderFunction) {
-
- Assert.notNull(builderFunction, "f must not be null");
-
- return builderFunction.apply(new Builder()).build();
- }
-
- /**
- * @since 5.2
- */
- public static Builder builder() {
- return new Builder();
- }
-
- /**
- * @since 5.2
- */
- public static final class Builder {
- @Nullable private ScriptType type;
- @Nullable private String language;
- @Nullable private String script;
- @Nullable private String scriptName;
- @Nullable private Map params;
-
- private Builder() {}
-
- public Builder withType(ScriptType type) {
-
- Assert.notNull(type, "type must not be null");
-
- this.type = type;
- return this;
- }
-
- public Builder withLanguage(@Nullable String language) {
- this.language = language;
- return this;
- }
-
- public Builder withScript(@Nullable String script) {
- this.script = script;
- return this;
- }
-
- public Builder withScriptName(@Nullable String scriptName) {
- this.scriptName = scriptName;
- return this;
- }
-
- public Builder withParams(@Nullable Map params) {
- this.params = params;
- return this;
- }
-
- public ScriptData build() {
-
- Assert.notNull(type, "type must be set");
-
- return new ScriptData(type, language, script, scriptName, params);
- }
- }
+public record ScriptData(@Nullable String language, @Nullable String script,
+ @Nullable String scriptName, @Nullable Map params) {
+
+ /*
+ * constructor overload to check the parameters
+ */
+ public ScriptData(@Nullable String language, @Nullable String script, @Nullable String scriptName,
+ @Nullable Map params) {
+
+ Assert.isTrue(script != null || scriptName != null, "script or scriptName is required");
+
+ this.language = language;
+ this.script = script;
+ this.scriptName = scriptName;
+ this.params = params;
+ }
+
+ /**
+ * factory method to create a ScriptData object.
+ *
+ * @since 5.2
+ */
+ public static ScriptData of(@Nullable String language, @Nullable String script,
+ @Nullable String scriptName, @Nullable Map params) {
+ return new ScriptData(language, script, scriptName, params);
+ }
+
+ /**
+ * factory method to create a ScriptData object using a ScriptBuilder callback.
+ *
+ * @param builderFunction function called to populate the builder
+ * @return
+ */
+ public static ScriptData of(Function builderFunction) {
+
+ Assert.notNull(builderFunction, "builderFunction must not be null");
+
+ return builderFunction.apply(new Builder()).build();
+ }
+
+ /**
+ * @since 5.2
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * @since 5.2
+ */
+ public static final class Builder {
+ @Nullable
+ private String language;
+ @Nullable
+ private String script;
+ @Nullable
+ private String scriptName;
+ @Nullable
+ private Map params;
+
+ private Builder() {
+ }
+
+ public Builder withLanguage(@Nullable String language) {
+ this.language = language;
+ return this;
+ }
+
+ public Builder withScript(@Nullable String script) {
+ this.script = script;
+ return this;
+ }
+
+ public Builder withScriptName(@Nullable String scriptName) {
+ this.scriptName = scriptName;
+ return this;
+ }
+
+ public Builder withParams(@Nullable Map params) {
+ this.params = params;
+ return this;
+ }
+
+ public ScriptData build() {
+ return new ScriptData(language, script, scriptName, params);
+ }
+ }
}
diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/ScriptType.java b/src/main/java/org/springframework/data/elasticsearch/core/query/ScriptType.java
deleted file mode 100644
index 1c6ceecab..000000000
--- a/src/main/java/org/springframework/data/elasticsearch/core/query/ScriptType.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2021-2025 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.data.elasticsearch.core.query;
-
-/**
- * Define script types for update queries.
- *
- * @author Farid Faoudi
- * @since 4.2
- */
-
-public enum ScriptType {
- INLINE, STORED
-}
diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/UpdateQuery.java b/src/main/java/org/springframework/data/elasticsearch/core/query/UpdateQuery.java
index 087f0c105..75959bb56 100644
--- a/src/main/java/org/springframework/data/elasticsearch/core/query/UpdateQuery.java
+++ b/src/main/java/org/springframework/data/elasticsearch/core/query/UpdateQuery.java
@@ -76,7 +76,7 @@ private UpdateQuery(String id, @Nullable String script, @Nullable Map : CoroutineCrudRepository, CoroutineSortingRepository
+interface CoroutineElasticsearchRepository : CoroutineCrudRepository, CoroutineSortingRepository
diff --git a/src/test/java/org/springframework/data/elasticsearch/client/elc/DocumentAdaptersUnitTests.java b/src/test/java/org/springframework/data/elasticsearch/client/elc/DocumentAdaptersUnitTests.java
index 1b9e60339..68dc1db7c 100644
--- a/src/test/java/org/springframework/data/elasticsearch/client/elc/DocumentAdaptersUnitTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/client/elc/DocumentAdaptersUnitTests.java
@@ -23,6 +23,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import org.assertj.core.api.SoftAssertions;
import org.assertj.core.data.Offset;
@@ -144,17 +145,17 @@ void shouldAdaptReturnedMatchedQueries() {
Hit searchHit = new Hit.Builder() //
.index("index") //
.id("42") //
- .matchedQueries("query1", "query2") //
+ .matchedQueries("query1", 1D) //
.build();
SearchDocument searchDocument = DocumentAdapters.from(searchHit, jsonpMapper);
SoftAssertions softly = new SoftAssertions();
- List matchedQueries = searchDocument.getMatchedQueries();
+ Map matchedQueries = searchDocument.getMatchedQueries();
softly.assertThat(matchedQueries).isNotNull();
- softly.assertThat(matchedQueries).hasSize(2);
- softly.assertThat(matchedQueries).isEqualTo(Arrays.asList("query1", "query2"));
+ softly.assertThat(matchedQueries).hasSize(1);
+ softly.assertThat(matchedQueries).isEqualTo(Map.of("query1",1D));
softly.assertAll();
}
}
diff --git a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchELCIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchELCIntegrationTests.java
index 884fde8d9..826c2e416 100644
--- a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchELCIntegrationTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchELCIntegrationTests.java
@@ -46,7 +46,6 @@
import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.data.elasticsearch.core.query.RescorerQuery;
import org.springframework.data.elasticsearch.core.query.ScriptData;
-import org.springframework.data.elasticsearch.core.query.ScriptType;
import org.springframework.data.elasticsearch.core.query.ScriptedField;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
import org.springframework.data.elasticsearch.utils.IndexNameProvider;
@@ -183,7 +182,7 @@ protected Query getMatchAllQueryWithIncludesAndInlineExpressionScript(@Nullable
return nativeQueryBuilder.withScriptedField(new ScriptedField( //
fieldName, //
- new ScriptData(ScriptType.INLINE, "expression", script, null, params))) //
+ new ScriptData( "expression", script, null, params))) //
.build();
}
diff --git a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchIntegrationTests.java
index 3a2e89212..195b11b3d 100755
--- a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchIntegrationTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchIntegrationTests.java
@@ -1630,7 +1630,6 @@ void shouldDoUpdateByQueryForExistingDocument() {
final Query query = operations.matchAllQuery();
final UpdateQuery updateQuery = UpdateQuery.builder(query)
- .withScriptType(ScriptType.INLINE)
.withScript("ctx._source['message'] = params['newMessage']").withLang("painless")
.withParams(Collections.singletonMap("newMessage", messageAfterUpdate)).withAbortOnVersionConflict(true)
.build();
diff --git a/src/test/java/org/springframework/data/elasticsearch/core/query/scriptedandruntimefields/ReactiveScriptedAndRuntimeFieldsIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/query/scriptedandruntimefields/ReactiveScriptedAndRuntimeFieldsIntegrationTests.java
index deef102e0..c17b4a8df 100644
--- a/src/test/java/org/springframework/data/elasticsearch/core/query/scriptedandruntimefields/ReactiveScriptedAndRuntimeFieldsIntegrationTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/core/query/scriptedandruntimefields/ReactiveScriptedAndRuntimeFieldsIntegrationTests.java
@@ -48,7 +48,6 @@
import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.data.elasticsearch.core.query.RuntimeField;
import org.springframework.data.elasticsearch.core.query.ScriptData;
-import org.springframework.data.elasticsearch.core.query.ScriptType;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository;
import org.springframework.data.elasticsearch.utils.IndexNameProvider;
@@ -165,7 +164,6 @@ private static org.springframework.data.elasticsearch.core.query.ScriptedField g
return org.springframework.data.elasticsearch.core.query.ScriptedField.of(
fieldName,
ScriptData.of(b -> b
- .withType(ScriptType.INLINE)
.withScript("doc['value'].size() > 0 ? doc['value'].value * params['factor'] : 0")
.withParams(Map.of("factor", factor))));
}
diff --git a/src/test/java/org/springframework/data/elasticsearch/core/query/scriptedandruntimefields/ScriptedAndRuntimeFieldsIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/query/scriptedandruntimefields/ScriptedAndRuntimeFieldsIntegrationTests.java
index 20f29ab66..d4b147d46 100644
--- a/src/test/java/org/springframework/data/elasticsearch/core/query/scriptedandruntimefields/ScriptedAndRuntimeFieldsIntegrationTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/core/query/scriptedandruntimefields/ScriptedAndRuntimeFieldsIntegrationTests.java
@@ -45,7 +45,6 @@
import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.data.elasticsearch.core.query.RuntimeField;
import org.springframework.data.elasticsearch.core.query.ScriptData;
-import org.springframework.data.elasticsearch.core.query.ScriptType;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.data.elasticsearch.utils.IndexNameProvider;
@@ -314,7 +313,6 @@ private static org.springframework.data.elasticsearch.core.query.ScriptedField b
return org.springframework.data.elasticsearch.core.query.ScriptedField.of(
fieldName,
ScriptData.of(b -> b
- .withType(ScriptType.INLINE)
.withScript("doc['value'].size() > 0 ? doc['value'].value * params['factor'] : 0")
.withParams(Map.of("factor", factor))));
}
diff --git a/src/test/resources/testcontainers-elasticsearch.properties b/src/test/resources/testcontainers-elasticsearch.properties
index 6860b4150..8784f82c3 100644
--- a/src/test/resources/testcontainers-elasticsearch.properties
+++ b/src/test/resources/testcontainers-elasticsearch.properties
@@ -15,7 +15,7 @@
#
#
sde.testcontainers.image-name=docker.elastic.co/elasticsearch/elasticsearch
-sde.testcontainers.image-version=8.18.1
+sde.testcontainers.image-version=9.0.2
#
#
# needed as we do a DELETE /* at the end of the tests, will be required from 8.0 on, produces a warning since 7.13