Created
December 27, 2019 05:16
-
-
Save svsh227/ed2530996c3c6427db1535969739b48a to your computer and use it in GitHub Desktop.
Integrate Elasticsearch With Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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