From f983436b52d9896ca319383562c459d5a91247f7 Mon Sep 17 00:00:00 2001 From: Peter-Josef Meisch Date: Wed, 6 Aug 2025 20:02:28 +0200 Subject: [PATCH] Upgrade Elasticsearch to 9.1.0 Signed-off-by: Peter-Josef Meisch --- pom.xml | 2 +- .../ROOT/pages/elasticsearch/elasticsearch-new.adoc | 2 +- .../modules/ROOT/pages/elasticsearch/versions.adoc | 2 +- .../client/elc/HighlightQueryBuilder.java | 11 +++++++---- .../elasticsearch/client/elc/IndicesTemplate.java | 12 +++++++++--- .../client/elc/ReactiveIndicesTemplate.java | 4 +++- .../testcontainers-elasticsearch.properties | 2 +- 7 files changed, 23 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 6d29a3b0d..98493ff36 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ 4.0.0-SNAPSHOT - 9.0.4 + 9.1.0 0.19.0 2.23.1 diff --git a/src/main/antora/modules/ROOT/pages/elasticsearch/elasticsearch-new.adoc b/src/main/antora/modules/ROOT/pages/elasticsearch/elasticsearch-new.adoc index 156a8e51e..a15bdf974 100644 --- a/src/main/antora/modules/ROOT/pages/elasticsearch/elasticsearch-new.adoc +++ b/src/main/antora/modules/ROOT/pages/elasticsearch/elasticsearch-new.adoc @@ -6,7 +6,7 @@ * Upgarde to Spring 7 * Switch to jspecify nullability annotations -* Upgrade to Elasticsearch 9.0.4 +* Upgrade to Elasticsearch 9.1.0 * Use the new Elasticsearch Rest5Client as default diff --git a/src/main/antora/modules/ROOT/pages/elasticsearch/versions.adoc b/src/main/antora/modules/ROOT/pages/elasticsearch/versions.adoc index bfb5916e8..e4b317540 100644 --- a/src/main/antora/modules/ROOT/pages/elasticsearch/versions.adoc +++ b/src/main/antora/modules/ROOT/pages/elasticsearch/versions.adoc @@ -6,7 +6,7 @@ The following table shows the Elasticsearch and Spring versions that are used by [cols="^,^,^,^",options="header"] |=== | Spring Data Release Train | Spring Data Elasticsearch | Elasticsearch | Spring Framework -| 2025.1 (in development) | 6.0.x | 9.0.4 | 7.0.x +| 2025.1 (in development) | 6.0.x | 9.1.0 | 7.0.x | 2025.0 | 5.5.x | 8.18.1 | 6.2.x | 2024.1 | 5.4.x | 8.15.5 | 6.1.x | 2024.0 | 5.3.xfootnote:oom[Out of maintenance] | 8.13.4 | 6.1.x diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/HighlightQueryBuilder.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/HighlightQueryBuilder.java index dfe850e4d..97a2c2794 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/HighlightQueryBuilder.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/HighlightQueryBuilder.java @@ -17,6 +17,8 @@ import static org.springframework.data.elasticsearch.client.elc.TypeUtils.*; +import co.elastic.clients.util.NamedValue; + import java.util.Arrays; import java.util.stream.Collectors; @@ -60,10 +62,11 @@ public co.elastic.clients.elasticsearch.core.search.Highlight getHighlight(Highl for (HighlightField highlightField : highlight.getFields()) { String mappedName = mapFieldName(highlightField.getName(), type); - highlightBuilder.fields(mappedName, hf -> { - addParameters(highlightField.getParameters(), hf, type); - return hf; - }); + highlightBuilder.fields( + NamedValue.of(mappedName, co.elastic.clients.elasticsearch.core.search.HighlightField.of(hf -> { + addParameters(highlightField.getParameters(), hf, type); + return hf; + }))); } return highlightBuilder.build(); diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/IndicesTemplate.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/IndicesTemplate.java index 5a735a724..dfd57efc3 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/IndicesTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/IndicesTemplate.java @@ -30,6 +30,7 @@ import org.jspecify.annotations.Nullable; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.data.elasticsearch.ResourceNotFoundException; import org.springframework.data.elasticsearch.UncategorizedElasticsearchException; import org.springframework.data.elasticsearch.annotations.Mapping; import org.springframework.data.elasticsearch.core.IndexInformation; @@ -315,15 +316,20 @@ public boolean putTemplate(PutTemplateRequest putTemplateRequest) { } @Override - public TemplateData getTemplate(GetTemplateRequest getTemplateRequest) { + public @Nullable TemplateData getTemplate(GetTemplateRequest getTemplateRequest) { Assert.notNull(getTemplateRequest, "getTemplateRequest must not be null"); co.elastic.clients.elasticsearch.indices.GetTemplateRequest getTemplateRequestES = requestConverter .indicesGetTemplateRequest(getTemplateRequest); - GetTemplateResponse getTemplateResponse = execute(client -> client.getTemplate(getTemplateRequestES)); - return responseConverter.indicesGetTemplateData(getTemplateResponse, getTemplateRequest.getTemplateName()); + try { + GetTemplateResponse getTemplateResponse = execute(client -> client.getTemplate(getTemplateRequestES)); + return responseConverter.indicesGetTemplateData(getTemplateResponse, getTemplateRequest.getTemplateName()); + } catch (ResourceNotFoundException e) { + // since Elasticsearch 9.1.0 we get an exception (404) instead of an empty result + return null; + } } @Override diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveIndicesTemplate.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveIndicesTemplate.java index 235905ce5..50d2e8871 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveIndicesTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveIndicesTemplate.java @@ -21,6 +21,7 @@ import co.elastic.clients.elasticsearch.indices.*; import co.elastic.clients.transport.ElasticsearchTransport; import co.elastic.clients.transport.endpoints.BooleanResponse; +import org.springframework.data.elasticsearch.ResourceNotFoundException; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -389,7 +390,8 @@ public Mono getTemplate(GetTemplateRequest getTemplateRequest) { co.elastic.clients.elasticsearch.indices.GetTemplateRequest getTemplateRequestES = requestConverter .indicesGetTemplateRequest(getTemplateRequest); Mono getTemplateResponse = Mono - .from(execute(client -> client.getTemplate(getTemplateRequestES))); + .from(execute(client -> client.getTemplate(getTemplateRequestES))) + .onErrorComplete(ResourceNotFoundException.class); return getTemplateResponse.flatMap(response -> { if (response != null) { diff --git a/src/test/resources/testcontainers-elasticsearch.properties b/src/test/resources/testcontainers-elasticsearch.properties index 0a1524ef5..2dd7fa868 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=9.0.4 +sde.testcontainers.image-version=9.1.0 # # # 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