/* * Insert document into cluster. */ report(data) { const {client, index, type} = this; // Insert document into cluster. return Promise.fromNode(cb => { client.index({index, type, body: data}, cb); }); }
/* * Close connection. */ close() { this.client.close(); }
/* * Ping connection. */ ping() { const client = this.client; return Promise.fromNode(cb => { client.ping(cb); }) .then(success => { if (!success) { return Promise.reject({ status: 502, message: 'Could not reach the elasticsearch instance!', }); } }); }
test('client.search with callback', function userLandCode (t) { resetAgent(done(t, 'POST', '/_search', '{"q":"pants"}')) agent.startTransaction('foo') var client = new elasticsearch.Client({ host: host }) var query = { q: 'pants' } client.search(query, function (err) { t.error(err) agent.endTransaction() agent.flush() }) })
async function testSearch () { const result = await client.search({ index, type, body: { query: { match: { 'Title': 'Hound' } } } }) console.log('testSearch', result) }
putTemplate(name, body) { this.client .indices .putTemplate({ name: name, body: body }); this.logElastic('info', `[TEMPLATE] created/updated [${name}]`); }
async bulk(body) { const response = await this.client .bulk({ body: body }); return (response.items.length > 0); }
test('client.search with abort', function userLandCode (t) { resetAgent(3, done(t, 'POST', '/_search', '{"q":"pants"}', true)) agent.startTransaction('foo') var client = new elasticsearch.Client({ host: host }) var query = { q: 'pants' } var req = client.search(query) setImmediate(() => { req.abort() agent.endTransaction() agent.flush() }) })
async putAlias(index, alias) { await this.client .indices .putAlias({ index: index, name: alias }); this.logElastic('info', `[ALIAS] successfully added alias [${alias}] to [${index}]!`); }
test('client.ping with promise', function userLandCode (t) { resetAgent(done(t, 'HEAD', '/')) agent.startTransaction('foo') var client = new elasticsearch.Client({ host: host }) client.ping().then(function () { agent.endTransaction() agent.flush() }, function (err) { t.error(err) }) })
test('client.ping with callback', function userLandCode (t) { resetAgent(done(t, 'HEAD', '/')) agent.startTransaction('foo') var client = new elasticsearch.Client({ host: host }) client.ping(function (err) { t.error(err) agent.endTransaction() agent.flush() }) })
test('client.count with callback', function userLandCode (t) { resetAgent(done(t, 'POST', '/_count')) agent.startTransaction('foo') var client = new elasticsearch.Client({ host: host }) client.count(function (err) { t.error(err) agent.endTransaction() agent.flush() }) })
/* * Insert document into cluster. */ report(data) { const {client, index, type} = this; // Insert document into cluster. return Promise.fromNode(cb => { client.index({index, type, body: data}, cb); }); }
/* * Close connection. */ close() { this.client.close(); }
/* * Ping connection. */ ping() { const client = this.client; return Promise.fromNode(cb => { client.ping(cb); }) .then(success => { if (!success) { return Promise.reject({ status: 502, message: 'Could not reach the elasticsearch instance!', }); } }); }