技术栈
python 3.11.8
neo4j 5.23.1
Python 脚本
# encoding: utf8
# author: qbit
# date: 2024-09-23
# summary: 清空 neo4j 全部索引
from neo4j import Record, GraphDatabase, RoutingControl
URI = "neo4j://192.168.1.97:7687"
AUTH = ("neo4j", "xxx")
def DropAllIndex():
r" 删除所有索引 "
with GraphDatabase.driver(URI, auth=AUTH) as driver:
gql = "SHOW INDEX;"
print(f"gql: {gql}")
records, summary, keys = driver.execute_query(
gql, database_="neo4j", routing_=RoutingControl.READ,
)
indexList = list()
for record in records:
record: Record
indexList.append(record['name'])
print(f"indexList: {indexList}")
for index in indexList:
gql = f"DROP INDEX {index}"
print(f"gql: {gql}")
records, summary, keys = driver.execute_query(
query_=gql,
database_="neo4j",
routing_=RoutingControl.WRITE
)
if __name__ == '__main__':
DropAllIndex()
后记
本文出自 qbit snap
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。