Guides / Sending and managing data / Manage indices and apps / Manage indices

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.

Before you delete an index, you may want to create a backup by exporting your index.

Deleting an index doesn’t affect its analytics data.

Deleting indices with replicas

If the index you want to delete is a replica of another index, you must first unlink it.

If the index is a primary index and has replicas, the replica indices will become independent indices if you delete their primary index.

Delete indices from the Algolia dashboard

To delete an index from the dashboard:

  1. Go to the Algolia dashboard and select your index from the Index menu.
  2. Select Manage index > Delete.

    Delete an index from the Algolia dashboard

  3. Type DELETE to confirm and click Delete.

Delete indices with the API

To delete an index, use the deleteIndex method with an API client or the algolia indices delete command with the Algolia CLI.

1
2
3
4
5
6
7
8
9
10
<?php
require_once __DIR__."/vendor/autoload.php";
use Algolia\AlgoliaSearch\SearchClient;

// Use an API key with `deleteIndex` ACL
$client = SearchClient::create(
  'YourApplicationID', 'YourAPIKey'
);
$index = $client->initIndex('indexName');
$index->delete();

Using API clients, you can only delete one index at a time.

Delete multiple indices

To delete more than one index, use listIndices to get an application’s indices and then use the multipleBatch method to delete multiple indices with a single API call. If you want to delete replica indices, you have to delete their primary indices first. You can delete multiple indices with the algolia indices delete command.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
require_once __DIR__."/vendor/autoload.php";
use Algolia\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){
    return !isset($index['primary']);
});

// Delete primary indices first
foreach ($primaryIndices as $i) {
  $index = $client->initIndex($i['name']);
  $index->delete()->wait();
}
echo "Deleted primary indices.\n";

// Now, delete replica indices
foreach ($replicaIndices as $i) {
  $index = $client.initIndex($i['name']);
  $index->delete()->wait();
}
echo "Deleted replica indices.\n";

Clear records from an index using the Algolia dashboard

If you only want to delete (clear) the records from an index, keeping the index configuration:

  1. Go to the Algolia dashboard and select your index from the Index menu.

    Delete all records from an index, keeping its configuration

  2. Type CLEAR to confirm and click Clear.

Clear records from an index using the API

To remove only the records from the index, while keeping the settings, synonyms, and Rules, use the clearObjects method with an API client or the algolia indices clear command .

1
2
3
4
5
6
7
8
9
10
<?php
require_once __DIR__."/vendor/autoload.php";
use Algolia\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";
Did you find this page helpful?