API: Need exact classes/code that will sort by geoDistance

My query is:

"query": {
//Some query here
"sort": [{
"_geo_distance": {
"location": {
"lat": 49.8693846,
"lon": -99.9405093
"order": "asc",
"unit": "m"

I need the code/hints which will let me form this sort at "query" level, programatically in Java.
Please quote any classes that i can use.

On another project, I wrote something like:

SearchRequest request = new SearchRequest(banoIndexName)
 .source(new SearchSourceBuilder()
 .sort(new GeoDistanceSortBuilder("location", lat, lon).sortMode(SortMode.AVG))


1 Like

Thanks !

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.