Nodejs opensearch client: how to useSQL

I’m converting from the elasticsearch to the opensearch nodejs library, and I’m struggling to get SQL queries to work.

I have:

import * as os from "@opensearch-project/opensearch"

const client = new os.Client({...})
await client.search({
    method: "POST",
    path: "/_plugins/_sql",
    body: {
      query: "select * from my_index"
    }
  })

This fails with “no overload matches this call”. It seems “method” is recognised, but path isn’t. Any suggestions?

In case I find the answer, I’ll post back here, but as this isn’t obvious, I thought I might as well put a topic here so others can find it.

If I remove path, the error response is: ResponseError: parsing_exception: [parsing_exception] Reason: Unknown key for a VALUE_STRING in [query].

Found the answer:

  const { body }  = await client.transport.request({
    method: "POST",
    path: "_plugins/_sql",
    body: {
      query: "select * from my_index"
    }
  })
1 Like