Skip to content

Instantly share code, notes, and snippets.

@svsh227
Created December 27, 2019 05:16
Show Gist options
  • Save svsh227/ed2530996c3c6427db1535969739b48a to your computer and use it in GitHub Desktop.
Save svsh227/ed2530996c3c6427db1535969739b48a to your computer and use it in GitHub Desktop.
Integrate Elasticsearch With Node.js
//deleteIndex.js
const elasticsearch = require('elasticsearch');
const indexName='demo_elastic_index';
const deleteIndex = async () => {
const client = new elasticsearch.Client({
host: 'localhost:9200',
// log: 'trace',
});
await client.ping({
requestTimeout: 3000
}, function (error) {
if (error) {
console.trace('elasticsearch cluster is down!');
} else {
console.log('Elastic search is running.');
}
});
try {
await client.indices.delete({index: indexName});
console.log('All index is deleted');
} catch (e) {
// console.log("Error in deleteing index",e);
if (e.status === 404) {
console.log('Index Not Found');
} else {
throw e;
}
}
}
deleteIndex();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment