把 CSV 导入 Neo4j 常用有 三种方式,从简单到专业依次是:
先找到 Neo4j 的 import 目录(默认在):
Neo4j/default.graphdb/import<neo4j-home>/import例如文件:
import/person.csv
LOAD CSVLOAD CSV WITH HEADERS FROM "file:///person.csv" AS row
CREATE (:Person {
id: row.id,
name: row.name,
age: toInteger(row.age)
})
✅ 适合:
neo4j-admin import(最快,适合大数据)⚠️ 只能在数据库为空时使用
persons.csvrelations.csvneo4j-admin import \
--nodes=import/persons.csv \
--relationships=import/relations.csv
✅ 适合:
from neo4j import GraphDatabase
driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password"))
with driver.session() as session:
with open("person.csv") as f:
next(f)
for line in f:
id, name, age = line.strip().split(",")
session.run(
"CREATE (:Person {id:$id, name:$name, age:$age})",
id=id, name=name, age=int(age)
)
✅ 适合:
toInteger / toFloatCALL db.index.fulltext.createNodeIndex如果你愿意,可以告诉我:
我可以直接帮你写 完整导入 Cypher 或命令。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。