- JavaScript Client: other versions:
- Introduction
- Installation
- Connecting
- Configuration
- Integrations
- API Reference
- Examples
- Client helpers
- Release notes
Basic configuration
editBasic configuration
editThis page shows you the possible basic configuration options that the clients offers.
const { Client } = require('@elastic/elasticsearch') const client = new Client({ node: 'http://localhost:9200', maxRetries: 5, requestTimeout: 60000, sniffOnStart: true })
|
The Elasticsearch endpoint to use. 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 } } |
|
Your authentication data. You can use both basic authentication and
ApiKey. Basic authentication: auth: { username: 'elastic', password: 'changeme' } ApiKey authentication: auth: { apiKey: 'base64EncodedKey' } Bearer authentication, useful for service account tokens. Be aware that it does not handle automatic token refresh: auth: { bearer: 'token' } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const client = new Client({ node: 'http://localhost:9200', proxy: 'http://localhost:8080' }) const client = new Client({ node: 'http://localhost:9200', proxy: 'http://user:pwd@localhost:8080' }) |
|
const client = new Client({ node: 'http://localhost:9200', agent: { agent: 'options' } }) const client = new Client({ node: 'http://localhost:9200', // the function takes as parameter the option // object passed to the Connection constructor agent: (opts) => new CustomAgent() }) const client = new Client({ node: 'http://localhost:9200', // Disable agent and keep-alive agent: false }) |
|
function defaultNodeFilter (node) { // avoid master only nodes if (node.roles.master === true && node.roles.data === false && node.roles.ingest === false) { return false } return true } |
|
function nodeSelector (connections) { const index = calculateIndex() return connections[index] } |
|
function generateRequestId (params, options) { // your id generation logic // must be syncronous return 'id' } |
|
|
|
|
|
|
|
|
|
|
|
const client = new Client({ cloud: { id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==' }, auth: { username: 'elastic', password: 'changeme' } }) |
|
|
|
|
|
|
|
|
Performances considerations
editBy default, the client will protection you against prototype poisoning attacks.
Read this article to learn more.
If needed you can disable prototype poisoning protection entirely or one of the two checks.
Read the secure-json-parse
documentation to learn more.
While it’s good to be safe, you should know that security always comes with a cost. With big enough payloads, this security check could causea drop in the overall performances, which might be a problem for your application. If you know you can trust the data stored in Elasticsearch, you can safely disable this check.
const client = new Client({ disablePrototypePoisoningProtection: true })
On this page