async getSettings(index) { const response = await this.client .indices .getSettings({ index: index, includeDefaults: true, human: true }); return response; }
const addmappingToIndex = async function(indexName, mappingType, mapping){ console.log(mapping); return await esClient.indices.putMapping({ index: indexName, type: mappingType, body: mapping }); }
function testMapping() { return ESClient.indices .getMapping({ index: "imdb" }) .then(result => { console.log("|Test Mapping|"); console.log("-----------------------------------"); console.log("Response Body: "); console.log(JSON.stringify(result)); }) .catch(err => console.error(`Error connecting to the es client: ${err}`)); }
/* ind = index */ function createIndex(ind) { return existsIndex(ind).then((resp) => { if(!resp) return client.indices.create({index: ind}) }) }
async getTemplate(name) { if (await this.client .indices .existsTemplate({ name: name })) { return await this.client .indices .getTemplate({ name: name }); } return; }
client.indices.delete({index: 'address'}, ( err, resp, status ) => { client.indices.create({ index: 'address' }, ( err, resp, status ) => { if (err) { console.log(err.message); } else { console.log("Successfully created address index"); } }); });
putTemplate(name, body) { this.client .indices .putTemplate({ name: name, body: body }); this.logElastic('info', `[TEMPLATE] created/updated [${name}]`); }
// delete and recreate an index async recreateIndex(name, indexConfig) { try { await this.client.indices.delete({ index: name }) } catch (err) { // catch in case the index doesn't already exist } await this.client.indices.create({ index: name, body: indexConfig, }) }
async getAlias(alias) { return await this.client .indices .getAlias({ name: alias }); }
async putAlias(index, alias) { await this.client .indices .putAlias({ index: index, name: alias }); this.logElastic('info', `[ALIAS] successfully added alias [${alias}] to [${index}]!`); }