Skip to content

Instantly share code, notes, and snippets.

@NGhebreial
Created November 2, 2022 09:00
Show Gist options
  • Save NGhebreial/9ba8c6b05ddc4e94499bbfcfce86a09e to your computer and use it in GitHub Desktop.
Save NGhebreial/9ba8c6b05ddc4e94499bbfcfce86a09e to your computer and use it in GitHub Desktop.
import fs from 'fs';
import algoliasearch from 'algoliasearch';
const IDS_FILE = './query_results.csv';
const indexName = ''; // The index we want
const client = algoliasearch('', ''); // The credentials
const index = client.initIndex(indexName);
const objectIds = fs.readFileSync(IDS_FILE, 'utf8').trim().split('\n').filter(x => /\d/.test(x)).map(x => x.replace(/"/g, ''));
index.deleteObjects(objectIds).then(({ objectIDs }) => {
console.log(`Sucessfully deleted ${objectIDs.length} documents`);
process.exit();
}).catch(e => console.log(e));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment