opensearch-project / opensearch-java

Java Client for OpenSearch
Apache License 2.0
105 stars 169 forks source link

GeoDistance sort with nested field #1031

Open aniskaziahmed opened 1 week ago

aniskaziahmed commented 1 week ago

Is your feature request related to a problem?

I am trying to sort the data using geo distance but the field is nested so I was trying provide a nested path but it seems there is no option available for that or it's clearly not visible/well documented how to do that.

What solution would you like?

A simple and easy way to add a nested path as we have that Sort Field

What alternatives have you considered?

I'd have to do the sorting in java unfortunately

This is the query that I have to build using java : ` GET /test/_search { "sort" : [ { "_geo_distance" : { "event_date.location.geo_coordinates": { "lat": 48.5073, "lon": 12.1601 }, //THIS IS MISSING "nested_path": "event_date",

              "order" : "desc",
              "unit" : "km",
              "mode" : "max",
              "distance_type" : "arc"
        }
    }
],

"query": { "match_all": { } } }

`

dblock commented 1 week ago

Looks like this is simply missing.

FYI, we have recently merged a beginning of a code generator that aims to resolve this entire class of problems (https://github.com/opensearch-project/opensearch-java/pull/366). There are a few things you can do to help:

  1. Ensure that the specification for these APIs in https://github.com/opensearch-project/opensearch-api-specification is correct, and add tests for them in that repo.
  2. Write tests in this repo for the scenarios that are broken like the ones you're reporting and manually fix any of these bugs.

The combination will ensure that as we switch to the generator we're not introducing regressions.