jdk安装:
jdk的版本要和neo4j相匹配
• jkd8 对应 neo4j3.5.16
• jdk11对应 neo4j4.0-4.3
neo4j下载:
官网下载地址: https://neo4j.com/download-center/
其他版本下载地址:https://we-yun.com/doc/neo4j/
neo4j环境配置
电脑属性—>高级系统属性—>环境变量
• 新建系统变量:NEO4J_HOME
• Path:路径 以及 %NEO4J_HOME%\bin
启动:
• 打开cmd
• 在bin目录下:neo4j.bat console
• 打开浏览器:http://localhost:7474/browser/
初始登录用户名和密码:neo4j
新密码:admin
语句
导入数据
LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MERGE (:Hero { name: line.tail});LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR','
MERGE (:Hero { name: line.head});
创建关系
LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label ='义女' MERGE (h1)-[:义女]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '义子' MERGE (h1)-[:义子]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label ='义父' MERGE (h1)-[:义父]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '徒弟' MERGE (h1)-[:徒弟]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '同事' MERGE (h1)-[:同事]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '妾' MERGE (h1)-[:妾]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '女儿' MERGE (h1)-[:女儿]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '让位' MERGE (h1)-[:让位]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '哥哥' MERGE (h1)-[:哥哥]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '义兄' MERGE (h1)-[:义兄]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '父亲' MERGE (h1)-[:父亲]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '朋友' MERGE (h1)-[:朋友]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '夫' MERGE (h1)-[:夫]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '主公' MERGE (h1)-[:主公]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '师傅' MERGE (h1)-[:师傅]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '臣' MERGE (h1)-[:臣]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '母亲' MERGE (h1)-[:母亲]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '岳母' MERGE (h1)-[:岳母]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '诸侯' MERGE (h1)-[:诸侯]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '同族' MERGE (h1)-[:同族]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '嫂子' MERGE (h1)-[:嫂子]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '儿子' MERGE (h1)-[:儿子]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '女婿' MERGE (h1)-[:女婿]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '堂弟' MERGE (h1)-[:堂弟]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '结拜' MERGE (h1)-[:结拜]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '叔叔' MERGE (h1)-[:叔叔]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '妻子' MERGE (h1)-[:妻子]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '弟弟' MERGE (h1)-[:弟弟]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '妹妹' MERGE (h1)-[:妹妹]->(h2);LOAD CSV WITH HEADERS FROM 'file:///sanguo.csv' AS line FIELDTERMINATOR ','
MATCH (h1:Hero),(h2:Hero) WHERE h1.name = line.head AND h2.name = line.tail AND line.label = '义弟' MERGE (h1)-[:义弟]->(h2);
查看关系
MATCH (n) RETURN n
查看特定关系图
RETURN (:Hero{name:"刘备"})-[*..1]->(:Hero)
创建索引:
PROFILE RETURN(:Hero{name:"刘备"})-[*..1]->(:Hero)
查看索引:
EXPLAIN RETURN(:Hero{name:"刘备"})-[*..1]->(:Hero)