async testConnection() { return this.client.cat.indices({ format: 'json' }); }
async query(query, values) { try { const result = (await this.sqlClient.sql.query({ // TODO cursor body: { query: SqlString.format(query, values) } })).body; // TODO: Clean this up, will need a better identifier than the cloud setting if (this.config.cloud) { const compiled = result.rows.map( r => result.columns.reduce((prev, cur, idx) => ({ ...prev, [cur.name]: r[idx] }), {}) ); return compiled; } return result && result.aggregations && this.traverseAggregations(result.aggregations); } catch (e) { if (e.body) { throw new Error(JSON.stringify(e.body, null, 2)); } throw e; } }
async tablesSchema() { const indices = await this.client.cat.indices({ format: 'json' }); const schema = (await Promise.all(indices.body.map(async i => { const props = (await this.client.indices.getMapping({ index: i.index })).body[i.index].mappings.properties || {}; return { [i.index]: Object.keys(props).map(p => ({ name: p, type: props[p].type })).filter(c => !!c.type) }; }))).reduce((a, b) => ({ ...a, ...b })); return { main: schema }; }
static async deleteIndexes (index) { if (index.length > 0) { return client.indices.delete({ index }) } return Promise.resolve() }
const searhState = async function searhState(state) { const { body } = await client.search({ index: 'bank', body: { query: { match: { state: state } } } }) return body.hits.hits }
client.count({ index: index_name }, (err) => { if (err) console.error(err); })
async updateIndex () { return client.indices.putSettings({ index: this.index, body: { settings: { index: { refresh_interval: '1s', number_of_replicas: config.ELASTIC_INDEX_REPLICAS } } } }) }
async bulkIndex () { const body = this.mapped.flatMap(doc => [{ index: { _index: this.index, _id: doc.nr } }, doc]) return client.bulk({ body }) }
async putAlias () { return client.indices.putAlias({ name: this.alias, index: this.index }) }
client.index({ id: event.pathParameters.Id, index: index_name, body: event.body }, (err, result) => { if (err) console.error(err); } )
async getIndexes () { return client.indices.get({ index: `${this.alias}-*` }) .then(({ body }) => body ? Object.keys(body).join() : '') }
client.search({ index: index_name, body: { query: { "match": { "_id": event.pathParameters.Id } } } },(err,result) => {if(err) console.error(err)})
const getAll = async function getAll() { const { body } = await client.search({ index: 'bank', size : 10000 }) return body.hits.hits }