If you delete an index, all records, rules, settings, and synonyms will be removed from your Algolia application.
The associated analytics data won’t be deleted.
If you accidentally delete an index,
the Algolia support
team might be able to restore it but there are no guarantees.
However, daily backups are included in the Enterprise pricing plan add-on.
Indices with replicas
In the dashboard, or using the API, you can’t delete a replica index directly.
You must first unlink it from the primary index.
If you delete a primary index, its replica indices become regular, independent indices.
You can delete replica indices with the Algolia CLI’s algolia indices delete command.
It handles the unlinking for you.
import"github.com/algolia/algoliasearch-client-go/v4/algolia/search"client,err:=search.NewClient("ALGOLIA_APPLICATION_ID","ALGOLIA_API_KEY")iferr!=nil{// The client can fail to initialize if you pass an invalid parameter.panic(err)}response,err:=client.DeleteIndex(client.NewApiDeleteIndexRequest("ALGOLIA_INDEX_NAME"))iferr!=nil{// handle the eventual errorpanic(err)}
fromalgoliasearch.search.clientimportSearchClientSyncfromjsonimportloads# In an asynchronous context, you can use SearchClient instead, which exposes the exact same methods.
client=SearchClientSync("ALGOLIA_APPLICATION_ID","ALGOLIA_API_KEY")response=client.delete_index(index_name="ALGOLIA_INDEX_NAME",)
namespaceAlgolia;usingSystem;usingSystem.Collections.Generic;usingSystem.Net.Http;usingSystem.Text.Json;usingAlgolia.Search.Clients;usingAlgolia.Search.Http;usingAlgolia.Search.Models.Search;classDeleteMultipleIndices{asyncTaskMain(string[]args){// You need an API key with `deleteIndex`varclient=newSearchClient(newSearchConfig("ALGOLIA_APPLICATION_ID","ALGOLIA_API_KEY"));// List all indicesvarindices=awaitclient.ListIndicesAsync();// Primary indices don't have a `primary` keyvarprimaryIndices=indices.Items.Where(item=>item.Primary==null).ToList();varreplicaIndices=indices.Items.Where(item=>item.Primary!=null).ToList();// Delete primary indices firstif(primaryIndices.Count>0){varrequests=primaryIndices.Select(index=>newMultipleBatchRequest(Search.Models.Search.Action.Delete,index.Name)).ToList();awaitclient.MultipleBatchAsync(newBatchParams{Requests=requests});Console.WriteLine("Deleted primary indices.");}// Now, delete replica indicesif(replicaIndices.Count>0){varrequests=replicaIndices.Select(index=>newMultipleBatchRequest(Search.Models.Search.Action.Delete,index.Name)).ToList();awaitclient.MultipleBatchAsync(newBatchParams{Requests=requests});Console.WriteLine("Deleted replica indices.");}}}
import'package:algolia_client_search/algolia_client_search.dart';voiddeleteMultipleIndices()async{// You need an API key with `deleteIndex`finalclient=SearchClient(appId:'ALGOLIA_APPLICATION_ID',apiKey:'ALGOLIA_API_KEY');// List all indicesfinalindices=awaitclient.listIndices();// Primary indices don't have a `primary` keyfinalprimaryIndices=indices.items.where((element)=>element.primary==null).toList();finalreplicaIndices=indices.items.where((element)=>element.primary!=null).toList();// Delete primary indices firstif(primaryIndices.isNotEmpty){finalList<MultipleBatchRequest>requests=primaryIndices.map((element)=>MultipleBatchRequest(action:Action.delete,indexName:element.name)).toList();awaitclient.multipleBatch(batchParams:BatchParams(requests:requests,),);print("Deleted primary indices.");}// Now, delete replica indicesif(replicaIndices.isNotEmpty){finalList<MultipleBatchRequest>requests=replicaIndices.map((element)=>MultipleBatchRequest(action:Action.delete,indexName:element.name)).toList();awaitclient.multipleBatch(batchParams:BatchParams(requests:requests,),);print("Deleted replica indices.");}}
packagemainimport("fmt""github.com/algolia/algoliasearch-client-go/v4/algolia/search")funcdeleteMultipleIndices(){// You need an API key with `deleteIndex`client,err:=search.NewClient("ALGOLIA_APPLICATION_ID","ALGOLIA_API_KEY")iferr!=nil{// The client can fail to initialize if you pass an invalid parameter.panic(err)}// List all indicesindices,err:=client.ListIndices(client.NewApiListIndicesRequest())iferr!=nil{panic(err)}// Primary indices don't have a `primary` keyprimaryIndices:=make([]search.FetchedIndex,len(indices.Items))replicaIndices:=make([]search.FetchedIndex,len(indices.Items))for_,index:=rangeindices.Items{ifindex.Primary==nil{primaryIndices=append(primaryIndices,index)}else{replicaIndices=append(replicaIndices,index)}}// Delete primary indices firstiflen(primaryIndices)>0{requests:=make([]search.MultipleBatchRequest,len(primaryIndices))for_,index:=rangeprimaryIndices{requests=append(requests,search.MultipleBatchRequest{Action:"delete",IndexName:index.Name,})}_,err=client.MultipleBatch(client.NewApiMultipleBatchRequest(search.NewEmptyBatchParams().SetRequests(requests)))iferr!=nil{panic(err)}fmt.Println("Deleted primary indices.")}// Now, delete replica indicesiflen(replicaIndices)>0{requests:=make([]search.MultipleBatchRequest,len(primaryIndices))for_,index:=rangeprimaryIndices{requests=append(requests,search.MultipleBatchRequest{Action:"delete",IndexName:index.Name,})}_,err=client.MultipleBatch(client.NewApiMultipleBatchRequest(search.NewEmptyBatchParams().SetRequests(requests)))iferr!=nil{panic(err)}fmt.Println("Deleted replica indices.")}}
packagecom.algolia;importcom.algolia.api.SearchClient;importcom.algolia.config.*;importcom.algolia.model.search.*;importjava.util.List;publicclassdeleteMultipleIndices{publicstaticvoidmain(String[]args)throwsException{// You need an API key with `deleteIndex`try(SearchClientclient=newSearchClient("ALGOLIA_APPLICATION_ID","ALGOLIA_API_KEY");){// List all indicesListIndicesResponseindices=client.listIndices();// Primary indices don't have a `primary` keyList<FetchedIndex>primaryIndices=indices.getItems().stream().filter(item->item.getPrimary()==null).toList();List<FetchedIndex>replicaIndices=indices.getItems().stream().filter(item->item.getPrimary()!=null).toList();// Delete primary indices firstif(!primaryIndices.isEmpty()){List<MultipleBatchRequest>requests=primaryIndices.stream().map(index->newMultipleBatchRequest().setAction(Action.DELETE).setIndexName(index.getName())).toList();client.multipleBatch(newBatchParams().setRequests(requests));System.out.println("Deleted primary indices.");}// Now, delete replica indicesif(!replicaIndices.isEmpty()){List<MultipleBatchRequest>requests=replicaIndices.stream().map(index->newMultipleBatchRequest().setAction(Action.DELETE).setIndexName(index.getName())).toList();client.multipleBatch(newBatchParams().setRequests(requests));System.out.println("Deleted replica indices.");}}catch(Exceptione){System.out.println("An error occurred: "+e.getMessage());}}}
importtype{MultipleBatchRequest}from'algoliasearch';import{algoliasearch}from'algoliasearch';// You need an API key with `deleteIndex`constclient=algoliasearch('ALGOLIA_APPLICATION_ID','ALGOLIA_API_KEY');// List all indicesconstindices=awaitclient.listIndices();// Primary indices don't have a `primary` keyconstprimaryIndices=indices.items.filter((item)=>item.primary==null);constreplicaIndices=indices.items.filter((item)=>item.primary!=null);// Delete primary indices firstif(primaryIndices.length>0){constrequests:MultipleBatchRequest[]=primaryIndices.map((index)=>({action:'delete',indexName:index.name,}));awaitclient.multipleBatch({requests:requests});console.log('Deleted primary indices.');}// Now, delete replica indicesif(replicaIndices.length>0){constrequests:MultipleBatchRequest[]=replicaIndices.map((index)=>({action:'delete',indexName:index.name,}));awaitclient.multipleBatch({requests:requests});console.log('Deleted replica indices.');}
importcom.algolia.client.api.SearchClientimportcom.algolia.client.configuration.*importcom.algolia.client.transport.*importcom.algolia.client.extensions.*importcom.algolia.client.model.search.*suspendfundeleteMultipleIndices(){// You need an API key with `deleteIndex`valclient=SearchClient(appId="ALGOLIA_APPLICATION_ID",apiKey="ALGOLIA_API_KEY")// List all indicesvalindices=client.listIndices()// Primary indices don't have a `primary` keyvalprimaryIndices=indices.items.filter{it.primary==null}valreplicaIndices=indices.items.filter{it.primary!=null}// Delete primary indices firstif(primaryIndices.isNotEmpty()){valrequests=primaryIndices.map{MultipleBatchRequest(action=Action.Delete,indexName=it.name,)}client.multipleBatch(batchParams=BatchParams(requests=requests,),)println("Deleted primary indices.")}// Now, delete replica indicesif(replicaIndices.isNotEmpty()){valrequests=replicaIndices.map{MultipleBatchRequest(action=Action.Delete,indexName=it.name,)}client.multipleBatch(batchParams=BatchParams(requests=requests,),)println("Deleted replica indices.")}}
<?phprequire__DIR__.'/../vendor/autoload.php';useAlgolia\AlgoliaSearch\Api\SearchClient;useAlgolia\AlgoliaSearch\Model\Search\Action;useAlgolia\AlgoliaSearch\Model\Search\MultipleBatchRequest;// You need an API key with `deleteIndex`$client=SearchClient::create('ALGOLIA_APPLICATION_ID','ALGOLIA_API_KEY');// List all indices$indicesResponse=$client->listIndices();$indices=$indicesResponse['items'];// Primary indices don't have a `primary` key$primaryIndices=array_filter($indices,function($index){return!isset($index['primary']);});$replicaIndices=array_filter($indices,function($index){returnisset($index['primary']);});// Delete primary indices firstif(!empty($primaryIndices)){$requests=array_map(function($index){return(newMultipleBatchRequest())->setAction((newAction())::DELETE)->setIndexName($index['name']);},$primaryIndices);$client->multipleBatch(['requests'=>$requests,],);echo"Deleted primary indices.\n";}// Now, delete replica indicesif(!empty($replicaIndices)){$requests=array_map(function($index){return['action'=>'delete','indexName'=>$index['name'],];},$replicaIndices);$client->multipleBatch(['requests'=>$requests,],);echo"Deleted replica indices.\n";}
fromalgoliasearch.search.clientimportSearchClientSync# You need an API key with `deleteIndex`
_client=SearchClientSync("ALGOLIA_APPLICATION_ID","ALGOLIA_API_KEY")# List all indices
indices=_client.list_indices()# Primary indices don't have a `primary` key
primary_indices=[indexforindexinindices.itemsifindex.primaryisNone]replica_indices=[indexforindexinindices.itemsifindex.primaryisnotNone]# Delete primary indices first
ifprimary_indices:requests=[{"action":"delete","indexName":index.name}forindexinprimary_indices]_client.multiple_batch(batch_params={"requests":requests,},)print("Deleted primary indices.")# Now, delete replica indices
ifreplica_indices:requests=[{"action":"delete","indexName":index.name}forindexinreplica_indices]_client.multiple_batch(batch_params={"requests":requests,},)print("Deleted replica indices.\n")
require"algolia"# You need an API key with `deleteIndex`client=Algolia::SearchClient.create("ALGOLIA_APPLICATION_ID","ALGOLIA_API_KEY")# List all indicesindices=client.list_indices# Primary indices don't have a `primary` keyprimary_indices,replica_indices=indices.items.partition{|index|index.primary.nil?}.map(&:to_a)# Delete primary indices firstifprimary_indices.any?requests=primary_indices.map{|index|Algolia::Search::BatchRequest.new(action: Algolia::Search::Action::DELETE,indexName: index.name)}client.multiple_batch(Algolia::Search::BatchParams.new(requests: requests))print("Deleted primary indices.")end# Now, delete replica indicesifreplica_indices.any?requests=replica_indices.map{|index|Algolia::Search::BatchRequest.new(action: Algolia::Search::Action::DELETE,indexName: index.name)}client.multiple_batch(Algolia::Search::BatchParams.new(requests: requests))print("Deleted replica indices.\n")end
importscala.concurrent.ExecutionContext.Implicits.globalimportscala.concurrent.Futureimportalgoliasearch.api.SearchClientimportalgoliasearch.config.*importalgoliasearch.extension.SearchClientExtensionsimportalgoliasearch.search.{Action,BatchParams,MultipleBatchRequest}defdeleteMultipleIndices():Future[Unit]={// You need an API key with `deleteIndex`valclient=SearchClient(appId="ALGOLIA_APPLICATION_ID",apiKey="ALGOLIA_API_KEY")client.listIndices().flatMap{indices=>val(primaryIndices,replicaIndices)=indices.items.partition(_.primary.isEmpty)valdeletePrimary=if(primaryIndices.nonEmpty){valrequests=primaryIndices.map(index=>MultipleBatchRequest(Action.Delete,None,index.name))client.multipleBatch(batchParams=BatchParams(requests=requests)).map{_=>println("Deleted primary indices.")}}elseFuture.unitvaldeleteReplica=if(replicaIndices.nonEmpty){valrequests=replicaIndices.map(index=>MultipleBatchRequest(Action.Delete,None,index.name))client.multipleBatch(batchParams=BatchParams(requests=requests)).map{_=>println("Deleted replica indices.")}}elseFuture.unitfor{_<-deletePrimary_<-deleteReplica}yield()}.recover{caseex:Exception=>println(s"An error occurred: ${ex.getMessage}")}}
importFoundation#if os(Linux) // For linux interopimportFoundationNetworking#endifimportCoreimportSearchfuncdeleteMultipleIndices()asyncthrows{do{// You need an API key with `deleteIndex`letclient=trySearchClient(appID:"ALGOLIA_APPLICATION_ID",apiKey:"ALGOLIA_API_KEY")// List all indicesletindices=tryawaitclient.listIndices()// Primary indices don't have a `primary` keyletprimaryIndices=indices.items.filter{$0.primary==nil}letreplicaIndices=indices.items.filter{$0.primary!=nil}// Delete primary indices firstifprimaryIndices.isEmpty==false{letrequests=primaryIndices.map{MultipleBatchRequest(action:.delete,indexName:$0.name)}tryawaitclient.multipleBatch(batchParams:BatchParams(requests:requests))print("Deleted primary indices.")}// Now, delete replica indicesifreplicaIndices.isEmpty==false{letrequests=replicaIndices.map{MultipleBatchRequest(action:.delete,indexName:$0.name)}tryawaitclient.multipleBatch(batchParams:BatchParams(requests:requests))print("Deleted replica indices.")}}catch{print(error)}}
Consider using the Algolia CLI. Its algolia indices delete
command lets you delete multiple indices and handles deleting replica indices for you.
Clear indices
If you clear an index, you just delete the records, but keep the settings, synonyms, and rules.
This is helpful if you want to reindex your records without changing the rest.
Delete all records from an index in the Algolia dashboard
import"github.com/algolia/algoliasearch-client-go/v4/algolia/search"client,err:=search.NewClient("ALGOLIA_APPLICATION_ID","ALGOLIA_API_KEY")iferr!=nil{// The client can fail to initialize if you pass an invalid parameter.panic(err)}response,err:=client.ClearObjects(client.NewApiClearObjectsRequest("ALGOLIA_INDEX_NAME"))iferr!=nil{// handle the eventual errorpanic(err)}
fromalgoliasearch.search.clientimportSearchClientSyncfromjsonimportloads# In an asynchronous context, you can use SearchClient instead, which exposes the exact same methods.
client=SearchClientSync("ALGOLIA_APPLICATION_ID","ALGOLIA_API_KEY")response=client.clear_objects(index_name="ALGOLIA_INDEX_NAME",)