Skip to content

Commit 8a164b1

Browse files
Adding GeoDistanceOrder's direction in request.
Original Pull Request #2602 Closes #2601
1 parent a2cbca5 commit 8a164b1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1497,8 +1497,9 @@ private SortOptions getSortOptions(Sort.Order order, @Nullable ElasticsearchPers
14971497
return SortOptions.of(so -> so //
14981498
.geoDistance(gd -> gd //
14991499
.field(fieldName) //
1500-
.location(loc -> loc.latlon(Queries.latLon(geoDistanceOrder.getGeoPoint())))//
1500+
.location(loc -> loc.latlon(Queries.latLon(geoDistanceOrder.getGeoPoint()))) //
15011501
.distanceType(geoDistanceType(geoDistanceOrder.getDistanceType())).mode(sortMode(finalMode)) //
1502+
.order(sortOrder(geoDistanceOrder.getDirection())) //
15021503
.unit(distanceUnit(geoDistanceOrder.getUnit())) //
15031504
.ignoreUnmapped(geoDistanceOrder.getIgnoreUnmapped())));
15041505
} else {

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

+15
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Map;
2929
import java.util.stream.Collectors;
3030

31+
import org.springframework.data.domain.Sort;
3132
import org.springframework.data.elasticsearch.core.RefreshPolicy;
3233
import org.springframework.data.elasticsearch.core.document.Document;
3334
import org.springframework.data.elasticsearch.core.query.*;
@@ -165,6 +166,20 @@ static GeoDistanceType geoDistanceType(GeoDistanceOrder.DistanceType distanceTyp
165166

166167
}
167168

169+
@Nullable
170+
static SortOrder sortOrder(@Nullable Sort.Direction direction) {
171+
172+
if (direction == null) {
173+
return null;
174+
}
175+
176+
return switch (direction) {
177+
case ASC -> SortOrder.Asc;
178+
case DESC -> SortOrder.Desc;
179+
};
180+
181+
}
182+
168183
@Nullable
169184
static HighlighterFragmenter highlighterFragmenter(@Nullable String value) {
170185

0 commit comments

Comments
 (0)