Neo4j的导入导出

导入csv文件
1、将csv文件放到import文件夹下(注意文件要是UTF-8的否则会乱码)
找到neo4j的安装路径,并在D:\neo4j-community-3.4.0\目录下创建import目录
完整路径如下D:\neo4j-community-3.4.0\import
因为neo4j支持导入csv文件,其默认目录入口是 …\import

-----------------讲解-------------------------------
这里有三个标签也就是(Lable):
分别是Genre、Person、Movie

这里用到的String转换int方法:
toInteger()
这里的p是节点(写不写都行)
p:后面是节点标签
{}大括号放的是节点里的属性
line代表的是文件(csv)的行
[]里放的是关系
actedin和is是关系
actedin{pid:toInteger(line.pid),mid:toInteger(line.mid)}
{pid:toInteger(line.pid),mid:toInteger(line.mid)}

pid 和mid一一对应
->是关系的指向
r代指关系
p代指节点

//导入节点 电影类型 == 注意类型转换
LOAD CSV WITH HEADERS FROM “file:///genre.csv” AS line
MERGE (p:Genre{gid:toInteger(line.gid),name:line.gname})

//导入节点 演员信息
LOAD CSV WITH HEADERS FROM ‘file:///person.csv’ AS line
MERGE (p:Person { pid:toInteger(line.pid),birth:line.birth,
death:line.death,name:line.name,
biography:line.biography,
birthplace:line.birthplace})

// 导入节点 电影信息
LOAD CSV WITH HEADERS  FROM "file:///movie.csv" AS line  
MERGE (p:Movie{mid:toInteger(line.mid),title:line.title,introduction:line.introduction,
rating:toFloat(line.rating),releasedate:line.releasedate})

// 导入关系 actedin  电影是谁参演的 1对多
LOAD CSV WITH HEADERS FROM "file:///person_to_movie.csv" AS line 
match (from:Person{pid:toInteger(line.pid)}),(to:Movie{mid:toInteger(line.mid)})  
merge (from)-[r:actedin{pid:toInteger(line.pid),mid:toInteger(line.mid)}]->(to)
	
//导入关系  电影是什么类型 == 1对多
LOAD CSV WITH HEADERS FROM "file:///movie_to_genre.csv" AS line
match (from:Movie{mid:toInteger(line.mid)}),(to:Genre{gid:toInteger(line.gid)})  
merge (from)-[r:is{mid:toInteger(line.mid),gid:toInteger(line.gid)}]->(to)


-- 问:章子怡都演了哪些电影?
match(n:Person)-[:actedin]->(m:Movie) where n.name='章子怡' return m.title

--  删除所有的节点及关系
MATCH (n)-[r]-(b)
DELETE n,r,b

注意:这个需要导入neo4j插件apoc
批量的动态的导入关系(apoc):
load csv with headers from "file:///people.csv" as line
       match(from:people{node_name:line.people1})
       match(to:people{node_name:line.people2})
       with from ,to ,line
       call apoc.create.relationship(from,line.relationship,{},to) yield rel
       return rel;

`

你可能感兴趣的:(neo4j,neo4j)