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.
Context object
editContext object
editSometimes, you might need to make some custom data available in your events, you can do that via the context
option of a request:
const { Client } = require('@elastic/elasticsearch') const client = new Client({ node: 'http://localhost:9200' }) client.on('request', (err, result) => { const { id } = result.meta.request const { context } = result.meta if (err) { console.log({ error: err, reqId: id, context }) } }) client.on('response', (err, result) => { const { id } = result.meta.request const { winter } = result.meta.context if (err) { console.log({ error: err, reqId: id, winter }) } }) client.search({ index: 'my-index', body: { foo: 'bar' } }, { context: { winter: 'is coming' } }, (err, result) => { if (err) console.log(err) })