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() }
async putAlias () { return client.indices.putAlias({ name: this.alias, index: this.index }) }
async getIndexes () { return client.indices.get({ index: `${this.alias}-*` }) .then(({ body }) => body ? Object.keys(body).join() : '') }
async updateIndex () { return client.indices.putSettings({ index: this.index, body: { settings: { index: { refresh_interval: '1s', number_of_replicas: config.ELASTIC_INDEX_REPLICAS } } } }) }
export default async function buildRegionsIndex( client: Client, indexId: string, regions: Region[] ) { await handleESError( client.indices.delete({ index: indexId, ignore_unavailable: true }) ); await handleESError( client.indices.create({ index: indexId, body: DEFINITION }) ); await bulkIndex(client, indexId, regions, true, "regionSearchId"); }
return client.indices.create(options)