How to perform GeoDistanceSort on a nested field using ES-8.5.3 JavaClient

We are using ElasticsearchClient instance to build our query and communicate with elasticsearch hosted on elastic-cloud version 8.5.3.

We could not find any information on how to inject nested path while creating GeoDistanceSort object.

Sort query that we are trying to convert to using Java:

"sort":[
      {
      "_geo_distance":{
          "nested":{
              "path":"facility"
           },
          "facility.location":{
            "lat":25.240995,
            "lon":55.751156
          },
          "unit":"km",
          "order":"asc",
          "mode" : "min",
          "distance_type" : "arc",
          "ignore_unmapped": true
        }
      }
   ]

Maven dependency:

<dependency>
  <groupId>co.elastic.clients</groupId>
  <artifactId>elasticsearch-java</artifactId>
  <version>8.5.3</version>
</dependency>

We have referred to the following official elastic documentation for JavaClient 8.5.3:

https://artifacts.elastic.co/javadoc/co/elastic/clients/elasticsearch-java/8.5.3/co/elastic/clients/elasticsearch/_types/SortOptions.html

https://artifacts.elastic.co/javadoc/co/elastic/clients/elasticsearch-java/8.5.3/co/elastic/clients/elasticsearch/_types/GeoDistanceSort.html

https://artifacts.elastic.co/javadoc/co/elastic/clients/elasticsearch-java/8.5.3/co/elastic/clients/elasticsearch/_types/GeoDistanceSort.Builder.html

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