-
Notifications
You must be signed in to change notification settings - Fork 4
/
elastic-delete-index.js
47 lines (44 loc) · 1.25 KB
/
elastic-delete-index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//const {Client} = require('@elastic/elasticsearch');
const { Client } = require('@opensearch-project/opensearch');
const configuration = require('./configuration.json');
const readline = require('node:readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
function askForConfirmation() {
return new Promise((resolve) => {
rl.question('Are you sure you want to proceed? (yes/no) ', (answer) => {
resolve(answer.trim().toLowerCase() === 'yes');
});
});
}
(async () => {
console.log('Deleting elastic index');
// Init elastic client
const client = new Client({
node: 'http://localhost:9200', //This is different from Oni since we are talking to it directly
});
// Bootstrap index
const elastic = configuration.api.elastic;
const index = elastic.index || 'items';
// Delete
try {
const confirmed = await askForConfirmation();
if (confirmed) {
const res = await client.indices.exists({
index,
});
if (res.statusCode !== 404) {
console.log('trying to delete the index');
await client.indices.delete({
index
});
}
}
} catch (e) {
console.log('index does not exist');
} finally {
rl.close();
}
})();