Basic options

edit

node or nodes

The Elasticsearch endpoint to use.
It can be a single string or an array of strings:

node: 'http://localhost:9200'

Or it can be an object (or an array of objects) that represents the node

node: {
  url: new URL('http://localhost:9200'),
  ssl: 'ssl options',
  agent: 'http agent options',
  id: 'custom node id',
  headers: { 'custom': 'headers' }
  roles: {
    master: true,
    data: true,
    ingest: true,
    ml: false
  }
}

maxRetries

number - Max number of retries for each request.
Default: 3

requestTimeout

number - Max request timeout for each request.
Default: 30000

pingTimeout

number - Max ping request timeout for each request.
Default: 3000

sniffInterval

number, boolean - Perform a sniff operation every n milliseconds.
Default: false

sniffOnStart

boolean - Perform a sniff once the client is started.
Default: false

sniffEndpoint

string - Endpoint to ping during a sniff.
Default: '_nodes/_all/http'

sniffOnConnectionFault

boolean - Perform a sniff on connection fault.
Default: false

resurrectStrategy

string - Configure the node resurrection strategy.
Options: 'ping', 'optimistic', 'none'
Default: 'ping'

suggestCompression

boolean - Adds accept-encoding header to every request.
Default: false

compression

string, boolean - Enables gzip request body compression.
Options: 'gzip', false
Default: false

ssl

http.SecureContextOptions - ssl configuraton.
Default: null

agent

http.AgentOptions, function - http agent options, or a function that returns an actual http agent instance.
Default: null

const client = new Client({
  node: 'http://localhost:9200',
  agent: { agent: 'options' }
})

const client = new Client({
  node: 'http://localhost:9200',
  agent: () => new CustomAgent()
})

nodeFilter

function - Filters which node not to use for a request.
Default:

function defaultNodeFilter (node) {
  // avoid master only nodes
  if (node.roles.master === true &&
      node.roles.data === false &&
      node.roles.ingest === false) {
    return false
  }
  return true
}

nodeSelector

function - custom selection strategy.
Options: 'round-robin', 'random', custom function
Default: 'round-robin'
Custom function example:

function nodeSelector (connections) {
  const index = calculateIndex()
  return connections[index]
}

generateRequestId

function - function to generate the request id for every request, it takes two parameters, the request parameters and options.
By default it generates an incremental integer for every request.
Custom function example:

function generateRequestId (params, options) {
  // your id generation logic
  // must be syncronous
  return 'id'
}

name

string - The name to identify the client instance in the events.
Default: elasticsearch-js

headers

object - A set of custom headers to send in every request.
Default: {}

cloud

object - Custom configuration for connecting to Elastic Cloud. See Authentication for more details.
Default: null
Cloud configuration example:

const client = new Client({
  cloud: {
    id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==',
    username: 'elastic',
    password: 'changeme'
  }
})