algolia / algoliasearch-client-javascript

⚡️ A fully-featured and blazing-fast JavaScript API client to interact with Algolia.

Home Page:https://www.algolia.com/doc/api-client/javascript/getting-started/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to delete virtual replica

lamontadams opened this issue · comments

How does one go about deleting a virtual replica index?

Looking at the published documentation at

It seems as though this should work, assuming a "main" index named "main" and a virtual replica named "virtual":

const client = algoliaSearch(ID, KEY);
const main = client.initIndex('main');
await main.setSettings({
    replicas: []
  });
const virtualIndex = client.initIndex('virtual');
await virtualIndex.delete();

However, the call to initIndex for 'virtual' yields this error response:

{
  name: 'ApiError',
  message: 'cannot apply a add object request on a replica index',
  status: 403,
}

Is there some way other than initIndex that I'm supposed to be getting a reference to a virtual replica index?

I'm not sure how you could have an "add object" error in code that doesn't mention addObject, but what I assume is happening is that your are waiting for the network requests, but not for the actual operations to be finished. You can opt in to that behaviour by writing await main.setSettings({}).wait() etc.

Yeah, thanks. That's what I'm apparently missing, my code seems to be racing the settings update of the main index.

The fact that this is needed isn't clear at all from any of the documentation I've looked at, and that error message is definitely less than helpful.

You received that error message from the API from the code you sent, without adding any new objects? That definitely seems like an issue I'll forward to the api team then!

Waiting for the tasks is in general not needed very often, but seems like it would be in this specific case where you want to recreate the same index as non-replica, and thus need to wait for the deletion to be done.

Yeah this is an unusual case for sure. I'm working around an issue with the terraform provider I'm using, which causes my script to fail when I apply it against an existing virtual replica index. Deleting existing virtual replicas beforehand is brute force but it does work around the issue...