File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
templates/python/guides/search Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 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())
You can’t perform that action at this time.
0 commit comments