WARNING: Version 5.x has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Client name
editClient name
editIf you are using multiple instances of the client or if you are using multiple child clients (which is the recommended way to have multiple instances of the client), you might need to recognize which client you are using, the name
options will help you in this regard:
const { Client } = require('@elastic/elasticsearch') const client = new Client({ node: 'http://localhost:9200', name: 'parent-client' // default to 'elasticsearch-js' }) const child = client.child({ name: 'child-client' }) console.log(client.name, child.name) client.on('request', (err, result) => { const { id } = result.meta.request const { name } = result.meta if (err) { console.log({ error: err, reqId: id, name }) } }) client.on('response', (err, result) => { const { id } = result.meta.request const { name } = result.meta if (err) { console.log({ error: err, reqId: id, name }) } }) client.search({ index: 'my-index', body: { foo: 'bar' } }, (err, result) => { if (err) console.log(err) }) child.search({ index: 'my-index', body: { foo: 'bar' } }, (err, result) => { if (err) console.log(err) })