Skip to content

Commit bec3beb

Browse files
authored
Upgrade to Elasticsearch 8.13.2.
Original Pull Request #2893 Closes #2891
1 parent 1d709f6 commit bec3beb

File tree

16 files changed

+35
-9
lines changed

16 files changed

+35
-9
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<springdata.commons>3.3.0-SNAPSHOT</springdata.commons>
2222

2323
<!-- version of the ElasticsearchClient -->
24-
<elasticsearch-java>8.12.2</elasticsearch-java>
24+
<elasticsearch-java>8.13.2</elasticsearch-java>
2525

2626
<blockhound-junit>1.0.8.RELEASE</blockhound-junit>
2727
<hoverfly>0.14.4</hoverfly>

src/main/antora/modules/ROOT/pages/elasticsearch/elasticsearch-new.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[[new-features.5-3-0]]
55
== New in Spring Data Elasticsearch 5.3
66

7-
* Upgrade to Elasticsearch 8.12.2.
7+
* Upgrade to Elasticsearch 8.13.2.
88
* Add support for highlight queries in highlighting.
99
* Add shard statistics to the `SearchHit` class.
1010
* Add support for multi search template API.

src/main/antora/modules/ROOT/pages/elasticsearch/versions.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The following table shows the Elasticsearch and Spring versions that are used by
66
[cols="^,^,^,^",options="header"]
77
|===
88
| Spring Data Release Train | Spring Data Elasticsearch | Elasticsearch | Spring Framework
9-
| 2024.0 (?) | 5.3.x | 8.12.2 | ?
9+
| 2024.0 (?) | 5.3.x | 8.13.2 | ?
1010
| 2023.1 (Vaughan) | 5.2.x | 8.11.1 | 6.1.x
1111
| 2023.0 (Ullmann) | 5.1.x | 8.7.1 | 6.0.x
1212
| 2022.0 (Turing) | 5.0.xfootnote:oom[Out of maintenance] | 8.5.3 | 6.0.x

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.springframework.data.elasticsearch.core.geo.GeoJson;
4040
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
4141
import org.springframework.data.elasticsearch.core.query.Criteria;
42+
import org.springframework.data.elasticsearch.utils.geohash.Geohash;
4243
import org.springframework.data.geo.Box;
4344
import org.springframework.data.geo.Distance;
4445
import org.springframework.data.geo.Metrics;
@@ -73,6 +74,9 @@ public static Optional<Query> createQuery(Criteria criteria) {
7374
queriesForEntries(chainedCriteria).forEach(boolQueryBuilder::should);
7475
filterQueries.add(new Query(boolQueryBuilder.build()));
7576
} else if (chainedCriteria.isNegating()) {
77+
78+
Assert.notNull(criteria.getField(), "criteria must have a field");
79+
7680
Collection<? extends Query> negatingFilters = buildNegatingFilter(criteria.getField().getName(),
7781
criteria.getFilterCriteriaEntries());
7882
filterQueries.addAll(negatingFilters);
@@ -116,6 +120,7 @@ private static Collection<? extends Query> buildNegatingFilter(String fieldName,
116120
private static Collection<? extends Query> queriesForEntries(Criteria criteria) {
117121

118122
Assert.notNull(criteria.getField(), "criteria must have a field");
123+
119124
String fieldName = criteria.getField().getName();
120125
Assert.notNull(fieldName, "Unknown field");
121126

@@ -177,7 +182,7 @@ private static ObjectBuilder<GeoDistanceQuery> withinQuery(String fieldName, Obj
177182
.distance(dist) //
178183
.distanceType(GeoDistanceType.Plane) //
179184
.location(location -> {
180-
if (values[0]instanceof GeoPoint loc) {
185+
if (values[0] instanceof GeoPoint loc) {
181186
location.latlon(latlon -> latlon.lat(loc.getLat()).lon(loc.getLon()));
182187
} else if (values[0] instanceof Point point) {
183188
GeoPoint loc = GeoPoint.fromPoint(point);
@@ -245,7 +250,7 @@ private static void twoParameterBBox(GeoBoundingBoxQuery.Builder queryBuilder, O
245250
Assert.isTrue(allElementsAreOfType(values, GeoPoint.class) || allElementsAreOfType(values, String.class),
246251
" both elements of boundedBy filter must be type of GeoPoint or text(format lat,lon or geohash)");
247252

248-
if (values[0]instanceof GeoPoint topLeft) {
253+
if (values[0] instanceof GeoPoint topLeft) {
249254
GeoPoint bottomRight = (GeoPoint) values[1];
250255
queryBuilder.boundingBox(bb -> bb //
251256
.tlbr(tlbr -> tlbr //
@@ -267,15 +272,19 @@ private static void twoParameterBBox(GeoBoundingBoxQuery.Builder queryBuilder, O
267272
.tlbr(tlbr -> tlbr //
268273
.topLeft(glb -> {
269274
if (isGeoHash) {
270-
glb.geohash(gh -> gh.geohash(topLeft));
275+
// although the builder in 8.13.2 supports geohash, the server throws an error, so we convert to a
276+
// lat,lon string here
277+
glb.text(Geohash.toLatLon(topLeft));
278+
// glb.geohash(gh -> gh.geohash(topLeft));
271279
} else {
272280
glb.text(topLeft);
273281
}
274282
return glb;
275283
}) //
276284
.bottomRight(glb -> {
277285
if (isGeoHash) {
278-
glb.geohash(gh -> gh.geohash(bottomRight));
286+
glb.text(Geohash.toLatLon(bottomRight));
287+
// glb.geohash(gh -> gh.geohash(bottomRight));
279288
} else {
280289
glb.text(bottomRight);
281290
}

src/test/java/org/springframework/data/elasticsearch/utils/geohash/Geohash.java renamed to src/main/java/org/springframework/data/elasticsearch/utils/geohash/Geohash.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import java.util.ArrayList;
1919
import java.util.Collection;
2020

21+
import org.springframework.util.Assert;
22+
2123
/**
2224
* Code copied from Elasticsearch 7.10, Apache License V2
2325
* https://github.com/elastic/elasticsearch/blob/7.10/libs/geo/src/main/java/org/elasticsearch/geometry/utils/Geohash.java
@@ -70,6 +72,21 @@ public static Point toPoint(final String geohash) throws IllegalArgumentExceptio
7072
return new Point(decodeLongitude(hash), decodeLatitude(hash));
7173
}
7274

75+
/**
76+
* Converts a geohash to a string in the format "lat,lon"
77+
*
78+
* @param geohash the geohash to convert
79+
* @return the lat lon pair in a String
80+
* @since 5.3
81+
*/
82+
public static String toLatLon(final String geohash) {
83+
84+
Assert.notNull(geohash, "geohash must not be null");
85+
86+
var point = Geohash.toPoint(geohash);
87+
return String.format("%f,%f", point.getLat(), point.getLon());
88+
}
89+
7390
/**
7491
* Computes the bounding box coordinates from a given geohash
7592
*
@@ -143,7 +160,7 @@ public static <E extends Collection<? super String>> E addNeighbors(String geoha
143160
* @return the given list
144161
*/
145162
public static <E extends Collection<? super String>> E addNeighborsAtLevel(String geohash, int level,
146-
E neighbors) {
163+
E neighbors) {
147164
String south = getNeighbor(geohash, level, 0, -1);
148165
String north = getNeighbor(geohash, level, 0, +1);
149166
if (north != null) {

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.12.2
18+
sde.testcontainers.image-version=8.13.2
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)