Guides / Sending and managing data / Manage your indices

Deletion will permanently remove an index and associated records from your application.

Deletion may not be your only option. If you want to reduce your usage, remove the records from an index (clear it) through either the dashboard’s Indices section or the API.

If you want to keep a backup of an index, export it. You can also save your index’s configuration data.

Deleting one index

To delete a single index, you can use the dashboard or API.

Delete an index using the dashboard

  1. Select an index.
  2. In the Browse tab, click the Manage index drop-down and select Delete.
  3. Confirm your request by typing DELETE into the pop-up box and then click Delete.

Delete an index using the API

Use the deleteIndex method on the index you want to delete.

1
$index->delete();

Deleting multiple indices using the API

You can’t delete multiple indices at once using the dashboard.

There isn’t a direct method to delete multiple indices, but you can write a script to loop through and delete the indices you want.

For example, if you’re running tests with indices that you generated with the prefix test_, you might want to purge them from your application from time to time.

Deleting all indices

  1. List all your indices.
  2. Loop through all primary indices and delete them.
  3. If you want to delete replica indices, you must detach them from their primary index. If there are replicas, wait for the deletion of their primary indices for them to automatically detach, then loop through and delete the replicas.
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
32
33
34
35
36
37
38
$indices = $client->listIndices();

// Delete primary indices only
$primaryIndices = array_filter($indices['items'], function ($index){
    return !isset($index['primary']);
});

$ops = array_map(function ($index) {
    return array(
        'indexName' => $index['name'],
        'action'    => 'delete'
    );
}, $primaryIndices);

$res = $client->multipleBatch($ops);

// Delete primary and replica indices. You need to delete the primary replicas first.
$primaryIndices = array_filter($indices['items'], function ($index){
    return !isset($index['primary']);
});
$replicaIndices = array_diff($indices['items'], $primaryIndices);

$ops = array_map(function ($index) {
    return array(
        'indexName' => $index['name'],
        'action'    => 'delete'
    );
}, $primaryIndices);
$res = $client->multipleBatch($ops);

$ops = array_map(function ($index) {
    return array(
        'indexName' => $index['name'],
        'action'    => 'delete'
    );
}, $replicaIndices);

$res = $client->multipleBatch($ops);

Deleting some indices

Deleting some indices is like deleting them all, except you must add a step to select the indices you want.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$indices = $client->listIndices();
$ops = array();

foreach ($indices['items'] as $index) {
    $indexName = $index['name'];
    if (strpos($indexName, 'test_') !== false) {
        array_push($ops, [
            'indexName' => $indexName,
            'action' => 'delete',
        ]);
    }
}

$res = $client->multipleBatch($ops);
Did you find this page helpful?