Skip to content

Commit a253d11

Browse files
p2c3 => delete index
1 parent a408e36 commit a253d11

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const elasticsearch = require('elasticsearch');
2+
const indexName='demo_elastic_index';
3+
const deleteIndex = async () => {
4+
const client = new elasticsearch.Client({
5+
host: 'localhost:9200',
6+
// log: 'trace',
7+
});
8+
await client.ping({
9+
requestTimeout: 3000
10+
}, function (error) {
11+
if (error) {
12+
console.trace('elasticsearch cluster is down!');
13+
} else {
14+
console.log('Elastic search is running.');
15+
}
16+
});
17+
try {
18+
await client.indices.delete({index: indexName});
19+
console.log('All index is deleted');
20+
} catch (e) {
21+
// console.log("Error in deleteing index",e);
22+
if (e.status === 404) {
23+
console.log('Index Not Found');
24+
} else {
25+
throw e;
26+
}
27+
}
28+
}
29+
deleteIndex();

0 commit comments

Comments
 (0)