Skip to content

Instantly share code, notes, and snippets.

@ahirel
Last active April 19, 2018 13:28
Show Gist options
  • Save ahirel/285ad181938526755d758db4e6e44d19 to your computer and use it in GitHub Desktop.
Save ahirel/285ad181938526755d758db4e6e44d19 to your computer and use it in GitHub Desktop.
// ObjectIDs = IDs of the
index.search({
query: documentId,
attributesToRetrieve: ['objectID'],
hitsPerPage: 100,
distinct: false,
}, function searchDone(err, content) {
if (err) {
console.error(err);
return;
}
// We get the IDs to delete (the current ones corresponding to the document)
const objectIDs = content.hits.map(hit => hit.objectID)
index.deleteObjects(objectIDs, function(error, content) {
if (!error) {
index.waitTask(content.taskID, function(err) {
if (err) {
console.log(err);
} else {
console.log('content', content)
// console.log('objects to add', objectsToAdd)
index.addObjects(objectsToAdd, function(e, content) {
// e ? true : console.log(content)
});
}
});
} else {
console.log(error)
}
});
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment