Skip to content

Commit c461cff

Browse files
committed
feat(python): deleteMultipleIndices
1 parent 03b89ee commit c461cff

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import asyncio
2+
{{> snippets/import}}
3+
4+
5+
async def main():
6+
try:
7+
# You need an API key with `deleteIndex`
8+
_{{> snippets/init}}
9+
10+
# List all indices
11+
indices = {{#dynamicSnippet}}listIndicesSimple{{/dynamicSnippet}}
12+
13+
# Primary indices don't have a `primary` key
14+
primary_indices = [index for index in indices.items if index.primary is None]
15+
replica_indices = [index for index in indices.items if index.primary is not None]
16+
17+
# Delete primary indices first
18+
if primary_indices:
19+
requests = [{'action': 'delete', 'indexName': index.name} for index in primary_indices]
20+
{{#dynamicSnippet}}deleteMultipleIndicesPrimary{{/dynamicSnippet}}
21+
print("Deleted primary indices.")
22+
23+
# Now, delete replica indices
24+
if replica_indices:
25+
requests = [{'action': 'delete', 'indexName': index.name} for index in replica_indices]
26+
{{#dynamicSnippet}}deleteMultipleIndicesReplica{{/dynamicSnippet}}
27+
print("Deleted replica indices.\n")
28+
29+
except Exception as e:
30+
print(f"Error: {e}")
31+
32+
asyncio.run(main())

0 commit comments

Comments
 (0)