Basic Auth

edit

You can provide your credentials in the node(s) URL.

const { Client } = require('@elastic/elasticsearch')
const client = new Client({
  node: 'https://username:password@localhost:9200'
})

Or you can use the full node declaration.

const { URL } = require('url')
const { Client } = require('@elastic/elasticsearch')
const client = new Client({
  node: {
    url: new URL('https://username:password@localhost:9200'),
    id: 'node-1',
    ...
  }
})