I was surprised to find out that there are differences between a direct REST call in Elastic and the exact same call in the Elastic JavaScript client.

The endpoint: _search

Curling to REST requires the sort portion of the request body to look like this:

{
  //...
  "sort": [
   {"field": {"order": "desc"}} 
  ],
  //...
}

Whereas for the JavaScript Client:

{
  //...
  "sort": ["field:desc"],
  //...
}

The latter does not work with the direct REST API which makes it seem like the documentation is actually wrong in REST documentation link.

In addition, any other qualifiers you can pass via REST are not exposed/available in the JavaScript client:

{
  //...
  "sort": [
   {"field": {"order": "desc", "numeric_type": "double"}} 
  ],
  //...
}

In the case I am working on we have float data that Elastic is incorrectly truncating to at most three numbers past the decimal. This results in wrong data in our tables when the sorted data is returned due to Elastic rounding.

"Casting" these floats as doubles coming back from the above REST call solves the problem in lieu of updating the mapping index to make these floats doubles. Considering that floats have more than enough precision, it is baffling why Elastic's internals do this truncation. That is a deep dive for another day.