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);