Getting a "Record quota exceeded" when quickly deleting and recreating my index

I am using the Community plan (for now), that includes 10k records.
I have a build script (gatsby-node.js#onPostBuild), that has a piece like this:

await algolia.deleteIndex('events') // contained 5027 objects
const index = algolia.initIndex('events')
await index.setSettings({/* some settings */})
await index.addObjects(objects) // array of 5027 objects

And when it is executed by Netlify, it fails with:

AlgoliaSearchError: Record quota exceeded, change plan or delete records.

But when I run it locally, it does not fail… should I add a little pause between the index deletion and the re-creation? Or maybe I should empty it instead of deleting it?
Any clue would be nice :slight_smile:

Thank you community!

You need to wait for more than just the request, since that doesn’t mean the task already finished. The correct way here if you are over 5k is to do:

const { taskID } = await algolia.deleteIndex('events')
await index.waitTask(taskID); has more information

1 Like

Thank you @haroen, works like a charm!
Sorry for missing this chapter of the awesome documentation!

1 Like

Also, I notice that if I have more than 5k records (and I’m still limited to 10k for now), If my batch contains a partialUpdateObjectNoCreate for each and every record, it fails with a Record quota exceeded too.
Looks like a bug to me :wink: