Can I change http client used for @elastic/elasticsearch in node js?

I want to use axios as http client underneath @elastic/elasticsearch....
I am trying using following code,

const { Client } = require('@elastic/elasticsearch');
const axios = require('axios');

// Create a custom transport using axios
const customTransport = connectionPool => ({
  request(params, callback) {
    const { method, path, body } = params;
    const url = connectionPool[0].makeUrl(params);

    axios({
      method,
      url,
      data: body,
      headers: params.headers,
    })
      .then(response => {
        callback(null, response.data, response.status, response.headers);
      })
      .catch(error => {
        callback(error);
      });
  },
});

// Create the Elasticsearch client with the custom transport
const client = new Client({
  node: 'http://localhost:9200',
  Transport: customTransport,
});

// Example usage
async function run() {
  const { body } = await client.info();
  console.log(body);
}```

run().catch(console.error);


Getting following error: 
PS C:\Users\ghabavis\dev\per\fake-reports> node .\test-axios-ransport.js
C:\Users\ghabavis\dev\per\fake-reports\node_modules\@elastic\elasticsearch\lib\client.js:185
        this.transport = new options.Transport({
                         ^

TypeError: options.Transport is not a constructor
    at new Client (C:\Users\ghabavis\dev\per\fake-reports\node_modules\@elastic\elasticsearch\lib\client.js:185:26)
    at Object.<anonymous> (C:\Users\ghabavis\dev\per\fake-reports\test-axios-ransport.js:26:16)
    at Module._compile (node:internal/modules/cjs/loader:1198:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
    at Module.load (node:internal/modules/cjs/loader:1076:32)
    at Function.Module._load (node:internal/modules/cjs/loader:911:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47

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