Skip to content

Commit 57390e4

Browse files
committed
Spring Data Elasticsearch 6.0 baseline
Signed-off-by: Andriy Redko <[email protected]>
1 parent 6270142 commit 57390e4

File tree

12 files changed

+44
-40
lines changed

12 files changed

+44
-40
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The Spring Data OpenSearch follows the release model of the Spring Data Elastics
2424

2525
| Spring Data Release Train | Spring Data OpenSearch | Spring Data Elasticsearch | OpenSearch Server | OpenSearch Client | Spring Framework | Spring Boot |
2626
|---------------------------|------------------------|---------------------------|-------------------|-------------------|------------------|---------------|
27+
| 2025.1 | 3.0.x | 6.0.x | 2.x / 3.x | 3.0.x and above | 7.0.x | 4.0.x |
2728
| 2025.0 | 2.0.x | 5.5.x | 2.x / 3.x | 3.0.x and above | 6.2.x | 3.5.x |
2829
| 2025.0 | 1.8.x | 5.5.x | 1.x / 2.x / 3.x | 2.10.x and above | 6.2.x | 3.5.x |
2930
| 2025.0 | 1.7.x | 5.5.x | 1.x / 2.x / 3.x | 2.10.x and above | 6.2.x | 3.5.x |

settings.gradle.kts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ dependencyResolutionManagement {
1616
}
1717

1818
create("springLibs") {
19-
version("spring", "6.2.8")
19+
version("spring", "7.0.0-M7")
2020
version("spring-boot", "3.5.3")
21-
library("data-commons", "org.springframework.data:spring-data-commons:3.5.2")
22-
library("data-elasticsearch", "org.springframework.data:spring-data-elasticsearch:5.5.2")
21+
library("data-commons", "org.springframework.data:spring-data-commons:4.0.0-M4")
22+
library("data-elasticsearch", "org.springframework.data:spring-data-elasticsearch:6.0.0-M4")
2323
library("web", "org.springframework", "spring-web").versionRef("spring")
2424
library("webflux", "org.springframework", "spring-webflux").versionRef("spring")
2525
library("context", "org.springframework", "spring-context").versionRef("spring")
@@ -32,7 +32,7 @@ dependencyResolutionManagement {
3232
library("boot-test", "org.springframework.boot", "spring-boot-test").versionRef("spring-boot")
3333
library("boot-test-autoconfigure", "org.springframework.boot", "spring-boot-test-autoconfigure").versionRef("spring-boot")
3434
library("boot-testcontainers", "org.springframework.boot", "spring-boot-testcontainers").versionRef("spring-boot")
35-
library("projectreactor", "io.projectreactor:reactor-test:3.7.8")
35+
library("projectreactor", "io.projectreactor:reactor-test:3.8.0-M4")
3636
plugin("spring-boot", "org.springframework.boot").versionRef("spring-boot")
3737
}
3838

@@ -77,12 +77,18 @@ pluginManagement {
7777
maven {
7878
url = uri("https://repo.spring.io/release/")
7979
}
80+
maven {
81+
url = uri("https://repo.spring.io/milestone/")
82+
}
8083
}
8184
}
8285

8386
dependencyResolutionManagement {
8487
repositories {
8588
mavenCentral()
89+
maven {
90+
url = uri("https://repo.spring.io/milestone/")
91+
}
8692
}
8793
}
8894

spring-data-opensearch/src/main/java/org/opensearch/data/client/orhlc/DocumentAdapters.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public static SearchDocument from(SearchHit source) {
190190

191191
NestedMetaData nestedMetaData = from(source.getNestedIdentity());
192192
Explanation explanation = from(source.getExplanation());
193-
List<String> matchedQueries = from(source.getMatchedQueries());
193+
Map<String, Double> matchedQueries = from(source.getMatchedQueriesAndScores());
194194

195195
BytesReference sourceRef = source.getSourceRef();
196196
Map<String, DocumentField> sourceFields = source.getFields();
@@ -263,8 +263,11 @@ private static NestedMetaData from(@Nullable SearchHit.NestedIdentity nestedIden
263263
}
264264

265265
@Nullable
266-
private static List<String> from(@Nullable String[] matchedQueries) {
267-
return matchedQueries == null ? null : Arrays.asList(matchedQueries);
266+
private static Map<String, Double> from(@Nullable Map<String, Float> matchedQueries) {
267+
return matchedQueries == null ? null : matchedQueries
268+
.entrySet()
269+
.stream()
270+
.collect(Collectors.toMap(Map.Entry::getKey, v -> v.getValue().doubleValue()));
268271
}
269272

270273
/**
@@ -539,7 +542,7 @@ static class SearchDocumentAdapter implements SearchDocument {
539542
private final Explanation explanation;
540543

541544
@Nullable
542-
private final List<String> matchedQueries;
545+
private final Map<String, Double> matchedQueries;
543546

544547
SearchDocumentAdapter(
545548
Document delegate,
@@ -550,7 +553,7 @@ static class SearchDocumentAdapter implements SearchDocument {
550553
Map<String, SearchDocumentResponse> innerHits,
551554
@Nullable NestedMetaData nestedMetaData,
552555
@Nullable Explanation explanation,
553-
@Nullable List<String> matchedQueries) {
556+
@Nullable Map<String, Double> matchedQueries) {
554557

555558
this.delegate = delegate;
556559
this.score = score;
@@ -751,7 +754,7 @@ public Explanation getExplanation() {
751754

752755
@Override
753756
@Nullable
754-
public List<String> getMatchedQueries() {
757+
public Map<String, Double> getMatchedQueries() {
755758
return matchedQueries;
756759
}
757760

spring-data-opensearch/src/main/java/org/opensearch/data/client/orhlc/RequestFactory.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@
115115
import org.springframework.data.elasticsearch.core.query.Query;
116116
import org.springframework.data.elasticsearch.core.query.RescorerQuery;
117117
import org.springframework.data.elasticsearch.core.query.RescorerQuery.ScoreMode;
118-
import org.springframework.data.elasticsearch.core.query.ScriptType;
119118
import org.springframework.data.elasticsearch.core.query.SourceFilter;
120119
import org.springframework.data.elasticsearch.core.query.StringQuery;
121120
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
@@ -1143,7 +1142,7 @@ public UpdateRequest updateRequest(UpdateQuery query, IndexCoordinates index) {
11431142
params = new HashMap<>();
11441143
}
11451144
Script script =
1146-
new Script(getScriptType(query.getScriptType()), query.getLang(), query.getScript(), params);
1145+
new Script(getScriptType(query.getScript()), query.getLang(), query.getScript(), params);
11471146
updateRequest.script(script);
11481147
}
11491148

@@ -1438,9 +1437,8 @@ private boolean hasSeqNoPrimaryTermProperty(@Nullable Class<?> entityClass) {
14381437
return entity.hasSeqNoPrimaryTermProperty();
14391438
}
14401439

1441-
private org.opensearch.script.ScriptType getScriptType(@Nullable ScriptType scriptType) {
1442-
1443-
if (scriptType == null || ScriptType.INLINE.equals(scriptType)) {
1440+
private org.opensearch.script.ScriptType getScriptType(@Nullable String script) {
1441+
if (script != null) {
14441442
return org.opensearch.script.ScriptType.INLINE;
14451443
} else {
14461444
return org.opensearch.script.ScriptType.STORED;
@@ -1449,16 +1447,14 @@ private org.opensearch.script.ScriptType getScriptType(@Nullable ScriptType scri
14491447

14501448
@Nullable
14511449
private Script getScript(UpdateQuery query) {
1452-
if (ScriptType.STORED.equals(query.getScriptType()) && query.getScriptName() != null) {
1450+
if (query.getScriptName() != null) { /* stored */
14531451
final Map<String, Object> params =
14541452
Optional.ofNullable(query.getParams()).orElse(new HashMap<>());
1455-
return new Script(getScriptType(ScriptType.STORED), null, query.getScriptName(), params);
1456-
}
1457-
1458-
if (ScriptType.INLINE.equals(query.getScriptType()) && query.getScript() != null) {
1453+
return new Script(getScriptType(query.getScript()), null, query.getScriptName(), params);
1454+
} else if (query.getScript() != null) { /* inline */
14591455
final Map<String, Object> params =
14601456
Optional.ofNullable(query.getParams()).orElse(new HashMap<>());
1461-
return new Script(getScriptType(ScriptType.INLINE), query.getLang(), query.getScript(), params);
1457+
return new Script(getScriptType(query.getScript()), query.getLang(), query.getScript(), params);
14621458
}
14631459

14641460
return null;

spring-data-opensearch/src/main/java/org/opensearch/data/client/osc/DocumentAdapters.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ public static SearchDocument from(Hit<?> hit, JsonpMapper jsonpMapper) {
138138

139139
float score = hit.score() != null ? hit.score().floatValue() : Float.NaN;
140140
return new SearchDocumentAdapter(document, score, hit.sort().stream().toArray(),
141-
documentFields, highlightFields, innerHits, nestedMetaData, explanation, matchedQueries, hit.routing());
141+
documentFields, highlightFields, innerHits, nestedMetaData, explanation,
142+
matchedQueries.stream().collect(Collectors.toMap(k -> k, v -> Double.NaN /* no scores */)),
143+
hit.routing());
142144
}
143145

144146
public static SearchDocument from(CompletionSuggestOption<EntityAsMap> completionSuggestOption) {

spring-data-opensearch/src/main/java/org/opensearch/data/client/osc/RequestConverter.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -776,14 +776,14 @@ private org.opensearch.client.opensearch._types.Script getScript(@Nullable Scrip
776776
scriptData.params().forEach((key, value) -> params.put(key, JsonData.of(value, jsonpMapper)));
777777
}
778778
return org.opensearch.client.opensearch._types.Script.of(sb -> {
779-
if (scriptData.type() == ScriptType.INLINE) {
779+
if (scriptData.script() != null) { /* inline */
780780
sb.inline(is -> is //
781781
.lang(fn -> fn.custom(scriptData.language())) //
782782
.source(scriptData.script()) //
783783
.params(params)); //
784-
} else if (scriptData.type() == ScriptType.STORED) {
784+
} else { /* stored */
785785
sb.stored(ss -> ss //
786-
.id(scriptData.script()) //
786+
.id(scriptData.scriptName()) //
787787
.params(params) //
788788
);
789789
}
@@ -1121,14 +1121,15 @@ public DeleteByQueryRequest documentDeleteByQueryRequest(Query query, @Nullable
11211121
}
11221122

11231123
uqb.script(sb -> {
1124-
if (query.getScriptType() == ScriptType.INLINE) {
1124+
// inline
1125+
if (query.getScript() != null) {
11251126
sb.inline(is -> is //
11261127
.lang(fn -> fn.custom(query.getLang())) //
11271128
.source(query.getScript()) //
11281129
.params(params)); //
1129-
} else if (query.getScriptType() == ScriptType.STORED) {
1130+
} else { /* stored */
11301131
sb.stored(ss -> ss //
1131-
.id(query.getScript()) //
1132+
.id(query.getScriptName()) //
11321133
.params(params) //
11331134
);
11341135
}

spring-data-opensearch/src/test/java/org/opensearch/data/client/core/document/DocumentAdaptersUnitTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ void shouldAdaptReturnedMatchedQueries() {
259259

260260
SearchDocument searchDocument = DocumentAdapters.from(searchHit);
261261

262-
List<String> matchedQueries = searchDocument.getMatchedQueries();
262+
Map<String, Double> matchedQueries = searchDocument.getMatchedQueries();
263263
assertThat(matchedQueries).isNotNull();
264264
assertThat(matchedQueries).hasSize(2);
265-
assertThat(matchedQueries).isEqualTo(Arrays.asList("query1", "query2"));
265+
assertThat(matchedQueries).isEqualTo(Map.of("query1", Double.NaN, "query2", Double.NaN));
266266
}
267267
}

spring-data-opensearch/src/test/java/org/opensearch/data/client/orhlc/OpenSearchORHLCIntegrationTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import org.springframework.data.elasticsearch.core.query.IndicesOptions;
5151
import org.springframework.data.elasticsearch.core.query.Query;
5252
import org.springframework.data.elasticsearch.core.query.RescorerQuery;
53-
import org.springframework.data.elasticsearch.core.query.ScriptType;
5453
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
5554
import org.springframework.data.elasticsearch.utils.IndexNameProvider;
5655
import org.springframework.lang.Nullable;
@@ -214,7 +213,6 @@ void shouldUseAllOptionsFromUpdateQuery() {
214213
.withIfSeqNo(42) //
215214
.withIfPrimaryTerm(13) //
216215
.withScript("script") //
217-
.withScriptType(ScriptType.INLINE)
218216
.withLang("lang") //
219217
.withRefreshPolicy(RefreshPolicy.WAIT_UNTIL) //
220218
.withRetryOnConflict(7) //
@@ -259,7 +257,6 @@ void shouldUseAllOptionsFromUpdateByQuery() throws JSONException {
259257
.withRequestsPerSecond(5F) //
260258
.withShouldStoreResult(false) //
261259
.withSlices(4) //
262-
.withScriptType(ScriptType.INLINE) //
263260
.withScript("script") //
264261
.withLang("painless") //
265262
.build(); //

spring-data-opensearch/src/test/java/org/opensearch/data/client/osc/DocumentAdaptersUnitTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616
package org.opensearch.data.client.osc;
1717

18-
import java.util.Arrays;
1918
import java.util.Collections;
2019
import java.util.List;
20+
import java.util.Map;
2121
import org.assertj.core.api.SoftAssertions;
2222
import org.assertj.core.data.Offset;
2323
import org.junit.jupiter.api.DisplayName;
@@ -154,10 +154,10 @@ void shouldAdaptReturnedMatchedQueries() {
154154

155155
SoftAssertions softly = new SoftAssertions();
156156

157-
List<String> matchedQueries = searchDocument.getMatchedQueries();
157+
Map<String, Double> matchedQueries = searchDocument.getMatchedQueries();
158158
softly.assertThat(matchedQueries).isNotNull();
159159
softly.assertThat(matchedQueries).hasSize(2);
160-
softly.assertThat(matchedQueries).isEqualTo(Arrays.asList("query1", "query2"));
160+
softly.assertThat(matchedQueries).isEqualTo(Map.of("query1", Double.NaN, "query2", Double.NaN));
161161
softly.assertAll();
162162
}
163163
}

spring-data-opensearch/src/test/java/org/opensearch/data/client/osc/OpenSearchOSCIntegrationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.springframework.data.elasticsearch.core.query.Query;
4545
import org.springframework.data.elasticsearch.core.query.RescorerQuery;
4646
import org.springframework.data.elasticsearch.core.query.ScriptData;
47-
import org.springframework.data.elasticsearch.core.query.ScriptType;
4847
import org.springframework.data.elasticsearch.core.query.ScriptedField;
4948
import org.springframework.data.elasticsearch.utils.IndexNameProvider;
5049
import org.springframework.lang.Nullable;
@@ -186,7 +185,7 @@ protected Query getMatchAllQueryWithIncludesAndInlineExpressionScript(@Nullable
186185

187186
return nativeQueryBuilder.withScriptedField(new ScriptedField( //
188187
fieldName, //
189-
new ScriptData(ScriptType.INLINE, "expression", script, null, params))) //
188+
new ScriptData("expression", script, null, params))) //
190189
.build();
191190
}
192191

0 commit comments

Comments
 (0)