-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
templates/dart/guides/search/deleteMultipleIndices.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{{> snippets/import}} | ||
|
||
void deleteMultipleIndices() async { | ||
// You need an API key with `deleteIndex` | ||
{{> snippets/init}} | ||
|
||
// List all indices | ||
var indices = await {{#dynamicSnippet}}listIndicesSimple{{/dynamicSnippet}}; | ||
|
||
// Primary indices don't have a `primary` key | ||
var primaryIndices = indices.items.where((element) => element.primary == null).toList(); | ||
var replicaIndices = indices.items.where((element) => element.primary != null).toList(); | ||
|
||
// Delete primary indices first | ||
if (primaryIndices.isNotEmpty) { | ||
List<MultipleBatchRequest> requests = primaryIndices.map((element) => | ||
MultipleBatchRequest( | ||
action: Action.delete, | ||
indexName: element.name | ||
) | ||
).toList(); | ||
await {{#dynamicSnippet}}deleteMultipleIndicesPrimary{{/dynamicSnippet}}; | ||
print("Deleted primary indices."); | ||
} | ||
|
||
// Now, delete replica indices | ||
if (replicaIndices.isNotEmpty) { | ||
List<MultipleBatchRequest> requests = replicaIndices.map((element) => | ||
MultipleBatchRequest( | ||
action: Action.delete, | ||
indexName: element.name | ||
) | ||
).toList(); | ||
await {{#dynamicSnippet}}deleteMultipleIndicesReplica{{/dynamicSnippet}}; | ||
print("Deleted replica indices."); | ||
} | ||
} |