NOTE: You are looking at documentation for an older release. 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) })