3939import org .springframework .data .elasticsearch .core .geo .GeoJson ;
4040import org .springframework .data .elasticsearch .core .geo .GeoPoint ;
4141import org .springframework .data .elasticsearch .core .query .Criteria ;
42+ import org .springframework .data .elasticsearch .utils .geohash .Geohash ;
4243import org .springframework .data .geo .Box ;
4344import org .springframework .data .geo .Distance ;
4445import 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 }
0 commit comments