Inject data with Node.js on Elasticsearch service

Hi,

I want to ingest data on Elasticsearch using a Node.js backend. The following link has instructions regarding how to the same on Elastic Cloud deployment (Ingest data with Node.js on Elasticsearch Service | Elasticsearch Service Documentation | Elastic). How can I do it in a local deployment ?

Thanks

Hi @Sheereen,

You'll need to specify the local deployment as the node parameter along with the required authentication params as auth dEpending on the security settings of your deployment. I would recommend taking a look at the JavaScript client connection documentation for self-managed.

Hope that helps!

1 Like

Thanks a lot.... was looking for this documentation.

I will try it out and let u know.

I am having trouble with certficates. Got the following error:

ConnectionError: self signed certificate in certificate chain
    at ClientRequest.onError (/root/Backend/ApiGateway/node_modules/@elastic/elasticsearch/lib/Connection.js:123:16)
    at ClientRequest.emit (node:events:527:28)
    at TLSSocket.socketErrorListener (node:_http_client:454:9)
    at TLSSocket.emit (node:events:527:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

The below is my server.js (node js file)

const client = new Client({
  node: elasticConfig.node,
  auth: {
    username: elasticConfig.username,
    password: elasticConfig.password
  },
  tls: {
    ca: fs.readFileSync(elasticConfig.ca),
    rejectUnauthorized: false
  }
})

Thanks for the update. I did come across this StackOverflow thread with a similar issue. Can you try rejectUnauthorized: true and also check the cert as it suggests?

Let us know if that solves the problem!

By default, in /etc/elasticsearch, I found a http_ca.crt file. I used the same as the ca certificate. Should I generate another in pem format?

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