Deleting an index permanently removes the records and the index configuration,
like searchable attributes and custom ranking, from your Algolia application.
Instead of deleting the complete index, you can also delete (clear) just the records,
keeping the configuration.
See Clear records from an index on this page for more information.
<?phprequire_once__DIR__."/vendor/autoload.php";useAlgolia\AlgoliaSearch\SearchClient;// Use an API key with `deleteIndex` ACL$client=SearchClient::create('YourApplicationID','YourAPIKey');$index=$client->initIndex('indexName');$index->delete();
1
2
3
4
5
6
7
8
require'algolia'# Use an API key with `deleteIndex` ACLclient=Algolia::Search::Client.create('YourApplicationID','YourAPIKey')index=client.init_index('indexName')index.delete
1
2
3
4
5
6
7
constalgoliasearch=require('algoliasearch');// Use an API key with `deleteIndex` ACLconstclient=algoliasearch('YourApplicationID','YourAPIKey');constindex=client.initIndex('indexName');index.delete();
1
2
3
4
5
6
fromalgoliasearch.search_clientimportSearchClient# Use an API key with `deleteIndex` ACL
client=SearchClient.create("YourApplicationID","YourAPIKey")index=client.init_index("indexName")index.delete()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
importAlgoliaSearchClient// Use an API key with `deleteIndex` ACLletclient=SearchClient(appID:"YourApplicationID",apiKey:"YourAPIKey")letindex=client.index(withName:"indexName")index.delete{resultinifcase.success(letresponse)=result{print("Response: \(response)")}}
1
2
3
4
5
6
7
8
// Use an API key with `deleteIndex` ACLvalclient=ClientSearch(ApplicationID("YourApplicationID"),APIKey("YourAPIKey"))valindex=client.initIndex(IndexName("indexName"))index.deleteIndex()
1
2
3
4
5
6
7
8
// Use an API key with `deleteIndex` ACLvarclient=newSearchClient("YourApplicationID","YourAPIKey");varindex=client.InitIndex("indexName");index.Delete();// Asynchronousawaitindex.DeleteAsync();
1
2
3
4
5
6
7
8
// Use an API key with `deleteIndex` ACLSearchClientclient=DefaultSearchClient.create("YourApplicationID","YourAPIKey");SearchIndex<Record>index=client.initIndex("indexName",Record.class);index.delete();//Asynchronousindex.deleteAsync();
1
2
3
4
// Use an API key with `deleteIndex` ACLclient:=search.NewClient('YourApplicationID','YourAPIKey')index:=client.InitIndex('indexName')res,err:=index.Delete()
1
2
3
// Use an API key with `deleteIndex` ACLvalclient=newAlgoliaClient("YourApplicationID","YourAPIKey")client.execute{deleteindex"index"}
1
algolia index delete <indexName>
Delete multiple indices
To delete more than one index,
use listIndices to get your indices and then use the multipleBatch method to delete multiple indices with a single API request.
<?phprequire_once__DIR__."/vendor/autoload.php";useAlgolia\AlgoliaSearch\SearchClient;// You need an API key with `deleteIndex` permissions$client=SearchClient::create('YourApplicationID','YourAPIKey');// List all indices$indices=$client->listIndices();// Primary indices don't have a `primary` key$primaryIndices=array_filter($indices['items'],function($index){return!isset($index['primary']);});$replicaIndices=array_filter($indices['items'],function($index){returnisset($index['primary']);});// Delete primary indices firstforeach($primaryIndicesas$i){$index=$client->initIndex($i['name']);$index->delete()->wait();}echo"Deleted primary indices.\n";// Now, delete replica indicesforeach($replicaIndicesas$i){$index=$client.initIndex($i['name']);$index->delete()->wait();}echo"Deleted replica indices.\n";
require'algolia'# You need an API key with `deleteIndex` permissionsclient=Algolia::Search::Client.create('YourAppplicationId','YourAPIKey')# List all indicesindices=client.list_indexes# Primary indices don't have a `primary` keyprimaryIndices,replicaIndices=indices[:items].partition{|index|index[:primary].nil?}# Delete primary indices firstclient.multiple_batch(primaryIndices.map{|index|{indexName: index[:name],action: 'delete'}}).waitputs'Deleted primary indices.'# Now, delete replica indicesclient.multiple_batch(replicaIndices.map{|index|{indexName: index[:name],action: 'delete'}})puts'Deleted replica indices.'
constalgoliasearch=require("algoliasearch");// You need an API key with `deleteIndex` permissionsconstclient=algoliasearch("YourApplicationID","YourAPIKey");// Use async/await syntax(async()=>{// List all indicesconstindices=awaitclient.listIndices();// Primary indices don't have a `primary` keyconstprimaryIndices=indices.items.filter((index)=>!index.primary);constreplicaIndices=indices.items.filter((index)=>index.primary);// Delete primary indices firstclient.multipleBatch(primaryIndices.map((index)=>{return{indexName:index.name,action:"delete"};})).wait();console.log("Deleted primary indices.");// Now, delete replica indicesclient.multipleBatch(replicaIndices.map((index)=>{return{indexName:index.name,action:"delete"};}));console.log("Deleted replica indices.");})();
fromalgoliasearch.search_clientimportSearchClient# You need an API key with `deleteIndex` permissions
client=SearchClient.create('YourApplicationID','YourAPIKey')# List all indices
indices=client.list_indices()primaries=[]replicas=[]forindexinindices["items"]:action={"indexName":index["name"],"action":"delete"}# Primary indices don't have a `primary` key
ifnot"primary"inindex:primaries.append(action)else:replicas.append(action)# Delete primary indices first
client.multiple_batch(primaries).wait()print("Deleted primary indices.")# Now, delete replica indices
client.multiple_batch(replicas)print("Deleted replica indices.")
importAlgoliaSearchClient// You need an API key with `deleteIndex`letclient=SearchClient(appID:"YourApplicationID",apiKey:"YourAPIKey")// List all indicesletindices=tryclient.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 firsttry!client.multipleBatchObjects(operations:primaryIndices)print("Deleted primary indices.")// Now, delete replica indicestry!client.multipleBatchObjects(operations:replicaIndices)print("Deleted replica indices.")
importcom.algolia.search.client.ClientSearchimportcom.algolia.search.model.APIKeyimportcom.algolia.search.model.ApplicationIDimportcom.algolia.search.model.indexing.BatchOperationimportcom.algolia.search.model.multipleindex.BatchOperationIndexsuspendfunmain(){// You need an API key with `deleteIndex` permissionvalclient=ClientSearch(applicationID=ApplicationID("YourApplicationID"),apiKey=APIKey("YourAPIKey"))// Primary indices don't have a `primary` keyval(primaryIndices,replicaIndices)=client.listIndices().items.partition{it.primaryOrNull==null}// Delete primary indices firstif(primaryIndices.isNotEmpty()){client.multipleBatchObjects(primaryIndices.map{BatchOperationIndex(it.indexName,BatchOperation.DeleteIndex)})println("Deleted primary indices.")}// Now, delete replica indicesif(replicaIndices.isNotEmpty()){client.multipleBatchObjects(replicaIndices.map{BatchOperationIndex(it.indexName,BatchOperation.DeleteIndex)})println("Deleted replica indices.")}}
usingSystem;usingSystem.Collections.Generic;usingAlgolia.Search.Clients;usingAlgolia.Search.Models.Batch;usingAlgolia.Search.Models.Enums;namespaceDeleteIndex{classProgram{staticvoidMain(string[]args){// You need an API key with `deleteIndex` permissionsvarclient=newSearchClient("YourApplicationID","YourAPIKey");// List all indicesvarindices=client.ListIndices().Items;varprimaryIndices=newList<BatchOperation<string>>();varreplicaIndices=newList<BatchOperation<string>>();foreach(varindexinindices){varaction=newBatchOperation<string>{IndexName=index.Name,Action=BatchActionType.Delete};// Primary indices don't have a `Primary` keyif(index.Primary==null){primaryIndices.Add(action);}else{replicaIndices.Add(action);}}// Delete primary indices firstif(primaryIndices.Count>0){client.MultipleBatch(primaryIndices).Wait();Console.WriteLine("Deleted primary indices.");}// Now, delete replica indicesif(replicaIndices.Count>0){client.MultipleBatch(replicaIndices);Console.WriteLine("Deleted replica indices.");}}}}
importcom.algolia.search.DefaultSearchClient;importcom.algolia.search.SearchClient;importcom.algolia.search.models.indexing.ActionEnum;importcom.algolia.search.models.indexing.BatchOperation;importcom.algolia.search.models.indexing.IndicesResponse;importjava.util.List;importjava.util.Map;importjava.util.stream.Collectors;publicclassProgram{publicstaticvoidmain(String[]args){// You need an API key with `deleteIndex` permissionsSearchClientclient=DefaultSearchClient.create("YourApplicationID","YourAPIKey");// List indices, primary indices don't have a `primary` keyMap<Boolean,List<IndicesResponse>>indices=client.listIndices().stream().collect(Collectors.partitioningBy(index->index.getPrimary()==null));List<IndicesResponse>primaryIndices=indices.get(true);List<IndicesResponse>replicaIndices=indices.get(false);// Delete primary indices firstif(!primaryIndices.isEmpty()){client.multipleBatch(primaryIndices.stream().map(index->newBatchOperation<>(index.getName(),ActionEnum.DELETE)).collect(Collectors.toList()));System.out.println("Deleted primary indices.");}// Now, delete replica indicesif(!replicaIndices.isEmpty()){client.multipleBatch(replicaIndices.stream().map(index->newBatchOperation<>(index.getName(),ActionEnum.DELETE)).collect(Collectors.toList()));System.out.println("Deleted replica indices.");}System.exit(0);}}
packagemainimport("fmt""github.com/algolia/algoliasearch-client-go/v3/algolia/search")funcmain(){// You need an API key with `deleteIndex` permissionsclient:=search.NewClient("YourApplicationID","YourAPIKey")// List all indicesindices,_:=client.ListIndices()varprimaryIndices[]search.BatchOperationIndexedvarreplicaIndices[]search.BatchOperationIndexedfor_,index:=rangeindices.Items{action:=search.BatchOperationIndexed{IndexName:index.Name,BatchOperation:search.BatchOperation{Action:search.Delete},}// Primary indices don't have a `Primary` keyifindex.Primary==""{primaryIndices=append(primaryIndices,action)}else{replicaIndices=append(replicaIndices,action)}}iflen(primaryIndices)>0{res,err:=client.MultipleBatch(primaryIndices)iferr!=nil{panic(err)}res.Wait()fmt.Println("Primary indices deleted")}iflen(replicaIndices)>0{_,err:=client.MultipleBatch(replicaIndices)iferr!=nil{panic(err)}fmt.Println("Replica indices deleted")}}
packageorg.exampleimportalgolia.AlgoliaClientimportalgolia.AlgoliaDsl._importalgolia.responses.Indicesimportscala.concurrent.Awaitimportscala.concurrent.ExecutionContext.Implicits.globalimportscala.concurrent.duration.Durationimportscala.language.postfixOpsobjectProgramextendsApp{// You need an API key with `deleteIndex` permissionvalclient=newAlgoliaClient("YourApplicationID","YourAPIKey")// List all indicesvalindices:Indices=Await.result(client.execute(listindices),Duration.Inf)// Primary indices don't have a `primary` keyval(primaryIndices,replicaIndices)=indices.items.partition(_.primary==null)// Delete primary indices firstfor(i<-primaryIndices.items){Await.result(client.execute(deleteindexi.name),Duration.Inf)}println("Deleted primary indices.")// Now, delete replica indicesfor(i<-replicaIndices.items){Await.result(client.execute(deleteindexi.name),Duration.Inf)}println("Deleted replica indices.")}
1
$ algolia index delete <INDEX_1> <INDEX_2> <INDEX_3>
Clear records from an index in the Algolia dashboard
If you only want to delete (clear) the records from an index, keeping the index configuration, follow these steps:
<?phprequire_once__DIR__."/vendor/autoload.php";useAlgolia\AlgoliaSearch\SearchClient;// You need an API key with `deleteIndex` permissions$client=SearchClient::create('YourApplicationID','YourAPIKey');$index=$client->initIndex('YourIndexName');$index->clearObjects();echo"Deleted records.\n";
1
2
3
4
5
6
7
8
require'algolia'# You need an API key with `deleteIndex` permissionsclient=Algolia::Search::Client.create('YourAppplicationID','YourAPIKey')index=client.init_index('YourIndexName')index.clear_objectsputs"Deleted records."
1
2
3
4
5
6
7
8
constalgoliasearch=require("algoliasearch");// You need an API key with `deleteIndex` permissionsconstclient=algoliasearch("YourApplicationID","YourAPIKey");constindex=client.initIndex("YourIndexName");index.clearObjects();console.log("Deleted records");
1
2
3
4
5
6
7
8
fromalgoliasearch.search_clientimportSearchClient# You need an API key with `deleteIndex` permissions
client=SearchClient.create("YourApplicationID","YourAPIKey")index=client.init_index("YourIndexName")index.clear_objects()print("Deleted records.")
importcom.algolia.search.client.ClientSearchimportcom.algolia.search.model.APIKeyimportcom.algolia.search.model.ApplicationIDimportcom.algolia.search.model.IndexNamesuspendfunmain(){// You need an API key with `deleteIndices` permissionvalclient=ClientSearch(applicationID=ApplicationID("YourApplicationID"),apiKey=APIKey("YourAPIKey"))valindex=client.initIndex(IndexName("YourIndexName"))index.clearObjects()println("Deleted records.")}
usingSystem;usingAlgolia.Search.Clients;namespaceClearObjects{classProgram{staticvoidMain(string[]args){// You need an API key with `deleteIndex` permissionsvarclient=newSearchClient("YourApplicationID","YourAPIKey");varindex=client.InitIndex("YourIndexName");index.ClearObjects();Console.WriteLine("Deleted records.");}}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
importcom.algolia.search.DefaultSearchClient;importcom.algolia.search.SearchClient;importcom.algolia.search.SearchIndex;publicclassProgram{publicstaticvoidmain(String[]args){// You need an API key with `deleteIndex` permissionsSearchClientclient=DefaultSearchClient.create("YourApplicationID","YourAPIKey");SearchIndexindex=client.initIndex("YourIndexName");index.clearObjects();System.out.println("Deleted records.");}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
packagemainimport("fmt""github.com/algolia/algoliasearch-client-go/v3/algolia/search")funcmain(){// You need an API key with `deleteIndex` permissionsclient:=search.NewClient("YourApplicationID","YourAPIKey")index:=client.InitIndex("YourIndexName")index.ClearObjects()fmt.Println("Deleted records.")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
packageorg.exampleimportalgolia.AlgoliaClientimportalgolia.AlgoliaDsl._importscala.concurrent.Awaitimportscala.concurrent.ExecutionContext.Implicits.globalimportscala.concurrent.duration.Durationimportscala.language.postfixOpsobjectProgramextendsApp{// You need an API key with `deleteIndex` permissionsvalclient=newAlgoliaClient("YourApplicationID","YourAPIKey")Await.result(client.execute(clearindex"YourIndexName"),Duration.Inf)println("Deleted records.")}