Atomic Index Swap and Delete

Hey Friends,

I've written a function that will take an index, make a new index named (temp-index), clone the index stuff, then atomically swap the names and drop the original index.
unfortunately each time on the updateAliases step I am met with

invalid_alias_name_exception
Root causes:
invalid_alias_name_exception: Invalid alias name <> an index or data stream exists with the same name as the alias

its in typescript but reads easily

    const tempIndex = `temp-${this.indexName}`;

    // Create a temporary index
    await client.indices.create({ index: tempIndex });

    // Mark the temporary index as read-only
    await this.changeIndexReadonlyStatus(tempIndex, true);


    // Clone the temporary index to the original index name
    await client.indices.clone({ index: tempIndex, target: this.indexName });

    // Update the aliases
    await client.indices.updateAliases({
      actions: [{ remove: { index: "*", alias: this.indexName } }, { add: { index: tempIndex, alias: this.indexName } }],
    });

    // Remove the read-only status from the original index
    await this.changeIndexReadonlyStatus(this.indexName, false);

hi @MikeGadget !

From what I see, what you're trying to do is to create an alias with the same name as an existing index.

You can't do that - you need a separate alias name to refer to the current index, clone it to the temp index, and then you can atomically change the alias to the temp index.

Keep in mind that aliases and indices are separate entities - you won't be able to create an alias with an existing index name.

Hope that helps!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.