Skip to content

Upgrade to Elasticsearch 8.13.2. #2893

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 2 commits into from
Apr 11, 2024
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>3.3.0-SNAPSHOT</springdata.commons>

<!-- version of the ElasticsearchClient -->
<elasticsearch-java>8.12.2</elasticsearch-java>
<elasticsearch-java>8.13.2</elasticsearch-java>

<blockhound-junit>1.0.8.RELEASE</blockhound-junit>
<hoverfly>0.14.4</hoverfly>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[[new-features.5-3-0]]
== New in Spring Data Elasticsearch 5.3

* Upgrade to Elasticsearch 8.12.2.
* Upgrade to Elasticsearch 8.13.2.
* Add support for highlight queries in highlighting.
* Add shard statistics to the `SearchHit` class.
* Add support for multi search template API.
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
| 2024.0 (?) | 5.3.x | 8.12.2 | ?
| 2024.0 (?) | 5.3.x | 8.13.2 | ?
| 2023.1 (Vaughan) | 5.2.x | 8.11.1 | 6.1.x
| 2023.0 (Ullmann) | 5.1.x | 8.7.1 | 6.0.x
| 2022.0 (Turing) | 5.0.xfootnote:oom[Out of maintenance] | 8.5.3 | 6.0.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.springframework.data.elasticsearch.core.geo.GeoJson;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import org.springframework.data.elasticsearch.core.query.Criteria;
import org.springframework.data.elasticsearch.utils.geohash.Geohash;
import org.springframework.data.geo.Box;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.Metrics;
Expand Down Expand Up @@ -73,6 +74,9 @@ public static Optional<Query> createQuery(Criteria criteria) {
queriesForEntries(chainedCriteria).forEach(boolQueryBuilder::should);
filterQueries.add(new Query(boolQueryBuilder.build()));
} else if (chainedCriteria.isNegating()) {

Assert.notNull(criteria.getField(), "criteria must have a field");

Collection<? extends Query> negatingFilters = buildNegatingFilter(criteria.getField().getName(),
criteria.getFilterCriteriaEntries());
filterQueries.addAll(negatingFilters);
Expand Down Expand Up @@ -116,6 +120,7 @@ private static Collection<? extends Query> buildNegatingFilter(String fieldName,
private static Collection<? extends Query> queriesForEntries(Criteria criteria) {

Assert.notNull(criteria.getField(), "criteria must have a field");

String fieldName = criteria.getField().getName();
Assert.notNull(fieldName, "Unknown field");

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

if (values[0]instanceof GeoPoint topLeft) {
if (values[0] instanceof GeoPoint topLeft) {
GeoPoint bottomRight = (GeoPoint) values[1];
queryBuilder.boundingBox(bb -> bb //
.tlbr(tlbr -> tlbr //
Expand All @@ -267,15 +272,19 @@ private static void twoParameterBBox(GeoBoundingBoxQuery.Builder queryBuilder, O
.tlbr(tlbr -> tlbr //
.topLeft(glb -> {
if (isGeoHash) {
glb.geohash(gh -> gh.geohash(topLeft));
// although the builder in 8.13.2 supports geohash, the server throws an error, so we convert to a
// lat,lon string here
glb.text(Geohash.toLatLon(topLeft));
// glb.geohash(gh -> gh.geohash(topLeft));
} else {
glb.text(topLeft);
}
return glb;
}) //
.bottomRight(glb -> {
if (isGeoHash) {
glb.geohash(gh -> gh.geohash(bottomRight));
glb.text(Geohash.toLatLon(bottomRight));
// glb.geohash(gh -> gh.geohash(bottomRight));
} else {
glb.text(bottomRight);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.ArrayList;
import java.util.Collection;

import org.springframework.util.Assert;

/**
* Code copied from Elasticsearch 7.10, Apache License V2
* https://github.com/elastic/elasticsearch/blob/7.10/libs/geo/src/main/java/org/elasticsearch/geometry/utils/Geohash.java
Expand Down Expand Up @@ -70,6 +72,21 @@ public static Point toPoint(final String geohash) throws IllegalArgumentExceptio
return new Point(decodeLongitude(hash), decodeLatitude(hash));
}

/**
* Converts a geohash to a string in the format "lat,lon"
*
* @param geohash the geohash to convert
* @return the lat lon pair in a String
* @since 5.3
*/
public static String toLatLon(final String geohash) {

Assert.notNull(geohash, "geohash must not be null");

var point = Geohash.toPoint(geohash);
return String.format("%f,%f", point.getLat(), point.getLon());
}

/**
* Computes the bounding box coordinates from a given geohash
*
Expand Down Expand Up @@ -143,7 +160,7 @@ public static <E extends Collection<? super String>> E addNeighbors(String geoha
* @return the given list
*/
public static <E extends Collection<? super String>> E addNeighborsAtLevel(String geohash, int level,
E neighbors) {
E neighbors) {
String south = getNeighbor(geohash, level, 0, -1);
String north = getNeighbor(geohash, level, 0, +1);
if (north != 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=8.12.2
sde.testcontainers.image-version=8.13.2
#
#
# 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