neo4j的下载安装就不说了
系统windows10
neo4j启动命令 neo4j.bat console
启动后根据打印的代码访问7474端口
一般的命令增删改查可以在网上随便找到就不写了
1.从csv文件导入数据
记得提前将文件放在neo4j文件夹的import目录下
line表示行
LOAD CSV WITH HEADERS FROM "file:///bank.csv" AS line CREATE(:Bank { name:line.bank, count:line.count})
2.从csv文件导入数据时创建关系
LOAD CSV WITH HEADERS FROM "file:///data.csv" AS line MATCH (s:Subject {subject: line.subject})
MATCH (o:Object {object: line.object})
CREATE (s)-[:Relation{type:line.predicate}]->(o)
3.合并名字或内容相同的节点
MATCH (n:Subject)
WITH n.subject AS subject, COLLECT(n) AS nodelist, COUNT(*) AS count
WHERE count > 1
CALL apoc.refactor.mergeNodes(nodelist) YIELD node
RETURN node
4.创建两个已有节点的关系
MATCH (p1:Phone{phoneNumber:"122****2828"}),(p2:Phone{phoneNumber:"193***2998"}) CREATE (p1)-[c:CONTACT]->(p2) RETURN c
4.连接MYSQL数据库导入数据
merge:遇见相同的节点的时候不再创建,否则创建
CALL apoc.load.jdbc(
'jdbc:mysql://localhost/kg?user=root&password=root&useUnicode=true&characterEncoding=utf8',
'select * from person'
) YIELD row
CREATE (f:Person {name: row.name})
MERGE (t:BirthAddress {address: row.birth_address})
CREATE (f)-[:BORN_IN]->(t)
5.根据id匹配数据
MATCH (n) WHERE id(n)=251 RETURN n