-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Nested sort seems to be missing #2376
Comments
For implementing nested sort there is a ticket #1783 Which version of Spring Data Elasticsearch are you referring to?
|
Yes, this api was on elastic 7. I've got it running on elastic 8.4 now with spring data 4.4.5. After upgrading to elastic 8.x, we switched over to org.springframework.data.elasticsearch.client.elc.NativeQueryBuilder. Just about everything works, but this nexted sort. That's a blocker since this search needs to sort by distance. |
I can't imagine we are the only ones that need to do a lat/lon nested query to sort by distance. #1783 looks pretty old and stale, how are we suppose to use elastic 8.x if it lack this? |
When you use
var sortOptions = new SortOptions.Builder()
.geoDistance(gd -> gd
.field("locationFieldName")
.location(loc -> loc
.latlon(latlon -> latlon
.lat(12.34)
.lon(23.45)
)
)
.unit(DistanceUnit.Miles)
)
.build();
var query = NativeQuery.builder().withSort(sortOptions).build(); or just: var query = NativeQuery.builder()
.withSort(sob -> sob
.geoDistance(gd -> gd
.field("locationFieldName")
.location(loc -> loc
.latlon(latlon -> latlon
.lat(12.34)
.lon(23.45)
)
)
.unit(DistanceUnit.Miles)
)
)
.build();
var order = new GeoDistanceOrder("locationFieldname", new GeoPoint(12.34, 23.45)).withUnit("miles");
var query = NativeQuery.builder().withSort(Sort.by(order)).build(); |
Thanks! That seems to get me a lot closer. From what I can see in the elastic documentation, there's suppose to be a 'path' in the nested query. At least I think that is the issue, any idea how I set that? |
The nested sort only seems available in the The But that's an Elasticsearch topic, not Spring Data Elasticsearch then. You might want to open an issue in Elastic's repository for the client at https://github.com/elastic/elasticsearch-java/issues |
before we used to be able to do
GeoDistanceSortBuilder geoDistanceSortBuilder = SortBuilders .geoDistanceSort(locationFieldName, poi.getFirst(), poi.getSecond()) .unit(DistanceUnit.MILES) .order(SortOrder.ASC); queryBuilder.withSort(geoDistanceSortBuilder);
now all I can do is
queryBuilder.withSort(Sort.by(Sort.Order.asc(locationField)));
just pass in a field, but need to do a nested query to generate a geo_distance field from which to sort on
The text was updated successfully, but these errors were encountered: