From 87be6dbd829febb43b868f41e378b281ad5573d5 Mon Sep 17 00:00:00 2001 From: Peter-Josef Meisch Date: Sat, 31 Dec 2022 00:30:58 +0100 Subject: [PATCH] Upgrade to Elasticsearch 7.17.8. Original Pull Request #2413 Closes #2401 --- pom.xml | 4 +-- src/main/asciidoc/preface.adoc | 2 +- ...elasticsearch-migration-guide-4.3-4.4.adoc | 4 +-- .../client/elc/DocumentAdapters.java | 5 ++-- .../client/elc/RequestConverter.java | 6 +++-- .../elasticsearch/client/elc/TypeUtils.java | 25 +++++++++++++++++++ .../testcontainers-elasticsearch.properties | 2 +- 7 files changed, 37 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 3f484cca7..31f680e75 100644 --- a/pom.xml +++ b/pom.xml @@ -19,9 +19,9 @@ - 7.17.7 + 7.17.8 - 7.17.7 + 7.17.8 2.17.1 4.1.65.Final 2.7.7-SNAPSHOT diff --git a/src/main/asciidoc/preface.adoc b/src/main/asciidoc/preface.adoc index 83135eee5..6a1ecbeab 100644 --- a/src/main/asciidoc/preface.adoc +++ b/src/main/asciidoc/preface.adoc @@ -37,7 +37,7 @@ built and tested. [cols="^,^,^,^,^",options="header"] |=== | Spring Data Release Train | Spring Data Elasticsearch | Elasticsearch | Spring Framework | Spring Boot -| 2021.2 (Raj) | 4.4.x | 7.17.7 | 5.3.x | 2.7.x +| 2021.2 (Raj) | 4.4.x | 7.17.8 | 5.3.x | 2.7.x | 2021.1 (Q) | 4.3.x | 7.15.2 | 5.3.x | 2.6.x | 2021.0 (Pascal) | 4.2.xfootnote:oom[Out of maintenance] | 7.12.0 | 5.3.x | 2.5.x | 2020.0 (Ockham)footnote:oom[] | 4.1.xfootnote:oom[] | 7.9.3 | 5.3.2 | 2.4.x diff --git a/src/main/asciidoc/reference/elasticsearch-migration-guide-4.3-4.4.adoc b/src/main/asciidoc/reference/elasticsearch-migration-guide-4.3-4.4.adoc index a477c4d77..ed70a1116 100644 --- a/src/main/asciidoc/reference/elasticsearch-migration-guide-4.3-4.4.adoc +++ b/src/main/asciidoc/reference/elasticsearch-migration-guide-4.3-4.4.adoc @@ -82,7 +82,7 @@ The dependencies for the new Elasticsearch client are still optional in Spring D co.elastic.clients elasticsearch-java - 7.17.7 + 7.17.8 commons-logging @@ -93,7 +93,7 @@ The dependencies for the new Elasticsearch client are still optional in Spring D org.elasticsearch.client elasticsearch-rest-client - 7.17.7 + 7.17.8 commons-logging diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/DocumentAdapters.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/DocumentAdapters.java index b90ae49e7..a87d87488 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/DocumentAdapters.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/DocumentAdapters.java @@ -138,9 +138,8 @@ final class DocumentAdapters { document.setPrimaryTerm(hit.primaryTerm() != null && hit.primaryTerm() > 0 ? hit.primaryTerm() : 0); float score = hit.score() != null ? hit.score().floatValue() : Float.NaN; - return new SearchDocumentAdapter(document, score, hit.sort().toArray(new String[0]), documentFields, - highlightFields, innerHits, nestedMetaData, explanation, matchedQueries, hit.routing()); - } + return new SearchDocumentAdapter(document, score, hit.sort().stream().map(TypeUtils::toString).toArray(), + documentFields, highlightFields, innerHits, nestedMetaData, explanation, matchedQueries, hit.routing()); } @Nullable private static Explanation from(@Nullable co.elastic.clients.elasticsearch.core.explain.Explanation explanation) { diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/RequestConverter.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/RequestConverter.java index 8edf02e7b..4de8ea638 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/RequestConverter.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/RequestConverter.java @@ -19,6 +19,7 @@ import static org.springframework.data.elasticsearch.client.elc.TypeUtils.*; import static org.springframework.util.CollectionUtils.*; import co.elastic.clients.elasticsearch._types.Conflicts; +import co.elastic.clients.elasticsearch._types.FieldValue; import co.elastic.clients.elasticsearch._types.InlineScript; import co.elastic.clients.elasticsearch._types.OpType; import co.elastic.clients.elasticsearch._types.SortOptions; @@ -754,7 +755,7 @@ class RequestConverter { ReindexRequest.Slice slice = source.getSlice(); if (slice != null) { - s.slice(sl -> sl.id(slice.getId()).max(slice.getMax())); + s.slice(sl -> sl.id(String.valueOf(slice.getId())).max(slice.getMax())); } if (source.getQuery() != null) { @@ -1168,7 +1169,8 @@ class RequestConverter { } if (!isEmpty(query.getSearchAfter())) { - builder.searchAfter(query.getSearchAfter().stream().map(Object::toString).collect(Collectors.toList())); + builder.searchAfter( + query.getSearchAfter().stream().map(it -> FieldValue.of(it.toString())).collect(Collectors.toList())); } query.getRescorerQueries().forEach(rescorerQuery -> { diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/TypeUtils.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/TypeUtils.java index f68533a82..847d9c502 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/TypeUtils.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/TypeUtils.java @@ -122,6 +122,31 @@ final class TypeUtils { return null; } + @Nullable + static String toString(@Nullable FieldValue fieldValue) { + + if (fieldValue == null) { + return null; + } + + switch (fieldValue._kind()) { + case Double: + return String.valueOf(fieldValue.doubleValue()); + case Long: + return String.valueOf(fieldValue.longValue()); + case Boolean: + return String.valueOf(fieldValue.booleanValue()); + case String: + return fieldValue.stringValue(); + case Null: + return null; + case Any: + return fieldValue.anyValue().toString(); + default: + throw new IllegalStateException("Unexpected value: " + fieldValue._kind()); + } + } + @Nullable static GeoDistanceType geoDistanceType(GeoDistanceOrder.DistanceType distanceType) { diff --git a/src/test/resources/testcontainers-elasticsearch.properties b/src/test/resources/testcontainers-elasticsearch.properties index 74c919c7c..c551372e4 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=7.17.7 +sde.testcontainers.image-version=7.17.8 # # # 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