opensearch-project / opensearch-js

Node.js Client for OpenSearch
https://opensearch.org/docs/latest/clients/javascript/
Apache License 2.0
185 stars 120 forks source link

[BUG] <title> SortCombinations typings lacking interfaces/types #850

Closed logan858 closed 3 days ago

logan858 commented 3 weeks ago

Describe the bug

I have a project where I'm converting from elasticsearch to opensearch, on a node/express server. (npm v @opensearch-project/opensearch@3.0.0-beta.3 )

I am noticing some (potential?) issues with the typings in this package, specifically the sort: image sortQuery: image image

my sortQuery func needs to return a SortCombinations compliant type object. In elasticsearch, the SortCombinations accomodates sorting by the field name with the SortOptions type like so: es typings: image

BUT, when we see the similar sort typings in os, it lacks the SortOptions of [property: string]: FieldSort | SortOrder | etc, etc. which allows the correct typings to be recognized for sorting by field names.
image

When using my own 'incorrectly' typed code it works perfectly fine to sort the opensearch results despite what the typings show , and in the opensearch docs it shows the functionality as one would expect: image

Related component

Search

To Reproduce

  1. Build an opensearch search query in ts/js.
  2. and a sort object to the body
  3. see typings mismatch

Expected behavior

typings should include field name sorting.

Additional Details

No response

logan858 commented 3 weeks ago

my temporary local fix: image image image

edit: (minus the format field, that doesnt seem to be supported by opensearch)

nhtruong commented 2 weeks ago

Thank you for bringing this to our attention. This incomplete typing for sort comes from the spec, which 3.x API is generated from. I've created an issue for it.

nhtruong commented 3 days ago

Closing as the spec has been updated and we're releasing beta.7 that includes the change.