Skip to content

Upgrade Elasticsearch to 9.1.0 #3147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<springdata.commons>4.0.0-SNAPSHOT</springdata.commons>

<!-- version of the ElasticsearchClient -->
<elasticsearch-java>9.0.4</elasticsearch-java>
<elasticsearch-java>9.1.0</elasticsearch-java>

<hoverfly>0.19.0</hoverfly>
<log4j>2.23.1</log4j>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -389,7 +390,8 @@ public Mono<TemplateData> getTemplate(GetTemplateRequest getTemplateRequest) {
co.elastic.clients.elasticsearch.indices.GetTemplateRequest getTemplateRequestES = requestConverter
.indicesGetTemplateRequest(getTemplateRequest);
Mono<GetTemplateResponse> getTemplateResponse = Mono
.from(execute(client -> client.getTemplate(getTemplateRequestES)));
.from(execute(client -> client.getTemplate(getTemplateRequestES)))
.onErrorComplete(ResourceNotFoundException.class);

return getTemplateResponse.flatMap(response -> {
if (response != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/testcontainers-elasticsearch.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down