client.indices.exists({ index: esParams.index }) .then((isExists) => { if (isExists) { return client.indices.delete({ index: esParams.index }); } return null; }) .then(() => client.indices.create({ index: esParams.index, body })) .then(() => { console.log('All done!'); }) .catch((err) => { console.log(err); }) ;