Skip to content

Commit c9c41f4

Browse files
authored
Upgrade to Elasticsearch 8.5.0. (#2348)
Original Pull Request #2348 Closes #2345 Closes #2300
1 parent 5da1994 commit c9c41f4

File tree

9 files changed

+47
-15
lines changed

9 files changed

+47
-15
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
<springdata.commons>3.0.0-SNAPSHOT</springdata.commons>
2222

2323
<!-- version of the RestHighLevelClient -->
24-
<elasticsearch-rhlc>7.17.6</elasticsearch-rhlc>
24+
<elasticsearch-rhlc>7.17.7</elasticsearch-rhlc>
2525
<!-- version of the new ElasticsearchClient -->
26-
<elasticsearch-java>8.4.3</elasticsearch-java>
26+
<elasticsearch-java>8.5.0</elasticsearch-java>
2727

2828
<log4j>2.18.0</log4j>
2929
<netty>4.1.65.Final</netty>

src/main/asciidoc/preface.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ built and tested.
3737
[cols="^,^,^,^,^",options="header"]
3838
|===
3939
| Spring Data Release Train | Spring Data Elasticsearch | Elasticsearch | Spring Framework | Spring Boot
40-
| 2022.0 (Turing) | 5.0.x | 8.4.3 | 6.0.x | 3.0.x?
40+
| 2022.0 (Turing) | 5.0.x | 8.5.0 | 6.0.x | 3.0.x?
4141
| 2021.2 (Raj) | 4.4.x | 7.17.3 | 5.3.x | 2.7.x
4242
| 2021.1 (Q) | 4.3.x | 7.15.2 | 5.3.x | 2.6.x
4343
| 2021.0 (Pascal) | 4.2.xfootnote:oom[Out of maintenance] | 7.12.0 | 5.3.x | 2.5.x

src/main/asciidoc/reference/elasticsearch-migration-guide-4.4-5.0.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,4 @@ The old deprecated `RestHighLevelClient` can still be used, but you will need to
159159
----
160160
====
161161

162-
Make sure to specify the version 7.17.6 explicitly, otherwise maven will resolve to 8.4.3, and this does not exist.
162+
Make sure to specify the version 7.17.6 explicitly, otherwise maven will resolve to 8.5.0, and this does not exist.

src/main/java/org/springframework/data/elasticsearch/client/elc/DocumentAdapters.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ public static SearchDocument from(Hit<?> hit, JsonpMapper jsonpMapper) {
138138
document.setPrimaryTerm(hit.primaryTerm() != null && hit.primaryTerm() > 0 ? hit.primaryTerm() : 0);
139139

140140
float score = hit.score() != null ? hit.score().floatValue() : Float.NaN;
141-
return new SearchDocumentAdapter(document, score, hit.sort().toArray(new String[0]), documentFields,
142-
highlightFields, innerHits, nestedMetaData, explanation, matchedQueries, hit.routing());
141+
return new SearchDocumentAdapter(document, score, hit.sort().stream().map(TypeUtils::toString).toArray(),
142+
documentFields, highlightFields, innerHits, nestedMetaData, explanation, matchedQueries, hit.routing());
143143
}
144144

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

src/main/java/org/springframework/data/elasticsearch/client/elc/RequestConverter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.springframework.util.CollectionUtils.*;
2020

2121
import co.elastic.clients.elasticsearch._types.Conflicts;
22+
import co.elastic.clients.elasticsearch._types.FieldValue;
2223
import co.elastic.clients.elasticsearch._types.InlineScript;
2324
import co.elastic.clients.elasticsearch._types.OpType;
2425
import co.elastic.clients.elasticsearch._types.SortOptions;
@@ -735,7 +736,7 @@ public co.elastic.clients.elasticsearch.core.ReindexRequest reindex(ReindexReque
735736

736737
ReindexRequest.Slice slice = source.getSlice();
737738
if (slice != null) {
738-
s.slice(sl -> sl.id(slice.getId()).max(slice.getMax()));
739+
s.slice(sl -> sl.id(String.valueOf(slice.getId())).max(slice.getMax()));
739740
}
740741

741742
if (source.getQuery() != null) {
@@ -1100,7 +1101,8 @@ public MsearchRequest searchMsearchRequest(
11001101
}
11011102

11021103
if (!isEmpty(query.getSearchAfter())) {
1103-
bb.searchAfter(query.getSearchAfter().stream().map(Object::toString).collect(Collectors.toList()));
1104+
bb.searchAfter(query.getSearchAfter().stream().map(it -> FieldValue.of(it.toString()))
1105+
.collect(Collectors.toList()));
11041106
}
11051107

11061108
query.getRescorerQueries().forEach(rescorerQuery -> bb.rescore(getRescore(rescorerQuery)));
@@ -1241,7 +1243,8 @@ private <T> void prepareSearchRequest(Query query, @Nullable Class<T> clazz, Ind
12411243
}
12421244

12431245
if (!isEmpty(query.getSearchAfter())) {
1244-
builder.searchAfter(query.getSearchAfter().stream().map(Object::toString).collect(Collectors.toList()));
1246+
builder.searchAfter(
1247+
query.getSearchAfter().stream().map(it -> FieldValue.of(it.toString())).collect(Collectors.toList()));
12451248
}
12461249

12471250
query.getRescorerQueries().forEach(rescorerQuery -> builder.rescore(getRescore(rescorerQuery)));

src/main/java/org/springframework/data/elasticsearch/client/elc/TypeUtils.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,37 @@ static FieldType fieldType(String type) {
9595
return null;
9696
}
9797

98+
@Nullable
99+
static String toString(@Nullable FieldValue fieldValue) {
100+
101+
if (fieldValue == null) {
102+
return null;
103+
}
104+
105+
switch (fieldValue._kind()) {
106+
case Double -> {
107+
return String.valueOf(fieldValue.doubleValue());
108+
}
109+
case Long -> {
110+
return String.valueOf(fieldValue.longValue());
111+
}
112+
case Boolean -> {
113+
return String.valueOf(fieldValue.booleanValue());
114+
}
115+
case String -> {
116+
return fieldValue.stringValue();
117+
}
118+
case Null -> {
119+
return null;
120+
}
121+
case Any -> {
122+
return fieldValue.anyValue().toString();
123+
}
124+
125+
default -> throw new IllegalStateException("Unexpected value: " + fieldValue._kind());
126+
}
127+
}
128+
98129
@Nullable
99130
static GeoDistanceType geoDistanceType(GeoDistanceOrder.DistanceType distanceType) {
100131

src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchELCIntegrationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ protected <A extends AggregationContainer<?>> void assertThatAggregationsAreCorr
104104
assertThat(bucketList.size()).isEqualTo(3);
105105
AtomicInteger count = new AtomicInteger();
106106
bucketList.forEach(stringTermsBucket -> {
107-
if ("message".equals(stringTermsBucket.key())) {
107+
if ("message".equals(stringTermsBucket.key().stringValue())) {
108108
count.getAndIncrement();
109109
assertThat(stringTermsBucket.docCount()).isEqualTo(3);
110110
}
111-
if ("some".equals(stringTermsBucket.key())) {
111+
if ("some".equals(stringTermsBucket.key().stringValue())) {
112112
count.getAndIncrement();
113113
assertThat(stringTermsBucket.docCount()).isEqualTo(2);
114114
}
115-
if ("other".equals(stringTermsBucket.key())) {
115+
if ("other".equals(stringTermsBucket.key().stringValue())) {
116116
count.getAndIncrement();
117117
assertThat(stringTermsBucket.docCount()).isEqualTo(1);
118118
}

src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsIntegrationTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ void shouldReturnEmptyListOnDerivedMethodWithEmptyInputList() {
266266
assertThat(products).isEmpty();
267267
}
268268

269-
@Disabled("issue #2300, Elasticsearch bug https://github.com/elastic/elasticsearch/issues/89760")
270269
@Test // #1909
271270
@DisplayName("should find by property exists")
272271
void shouldFindByPropertyExists() {
@@ -276,7 +275,6 @@ void shouldFindByPropertyExists() {
276275
assertThat(searchHits.getTotalHits()).isEqualTo(6);
277276
}
278277

279-
@Disabled("issue #2300, Elasticsearch bug https://github.com/elastic/elasticsearch/issues/89760")
280278
@Test // #1909
281279
@DisplayName("should find by property is not null")
282280
void shouldFindByPropertyIsNotNull() {

src/test/resources/testcontainers-elasticsearch.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#
1616
#
1717
sde.testcontainers.image-name=docker.elastic.co/elasticsearch/elasticsearch
18-
sde.testcontainers.image-version=8.4.3
18+
sde.testcontainers.image-version=8.5.0
1919
#
2020
#
2121
# 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

0 commit comments

Comments
 (0)