一、安装
官网下载,https://neo4j.com
二、Neo4j的查询语言Cypher的基本使用
1、CREATE (you:Person {name:"chenjie"}) RETURN you
2、MATCH (you:Person {name:"chenjie"}) CREATE (you)-[like:LIKE]->(neo:Database {name:"Neo4j" }) RETURN you,like,neo
3、MATCH (you:Person {name:"chenjie"}) FOREACH (name in ["Johan","Rajesh","Anna","Julia","Andrew"] | CREATE (you)-[:FRIEND]->(:Person {name:name}))
MATCH (you {name:"chenjie"})-[:FRIEND]->(yourFriends) RETURN you, yourFriends
4、MATCH (neo:Database {name:"Neo4j"})
MATCH (anna:Person {name:"Anna"})
CREATE (anna)-[:FRIEND]->(:Person:Expert {name:"Amanda"})-[:WORKED_WITH]->(neo)
5、MATCH (you {name:"chenjie"})
MATCH (expert)-[:WORKED_WITH]->(db:Database {name:"Neo4j"})
MATCH path = shortestPath( (you)-[:FRIEND*..5]-(expert) )
RETURN db,expert,path
CREATE (star:Star {id:"2012",name:"高圆圆"})
RETURN star
MATCH (star:Star {id:"2012"}) CREATE (star)-[workas:WORKAS]->(job:JOB {name:"演员" }) RETURN star,workas,job
MATCH (star:Star {id:"2012"}) CREATE (star)-[workas:WORKAS]->(job:JOB {name:"模特" }) RETURN star,workas,job
MATCH (star:Star {id:"2012"})-[workas:WORKAS]->(job:JOB) return star,workas,job
MATCH (star:Star {id:"2012"}) CREATE (star)-[xingzuowith:XINGZUOWITH]->(xingzuo:XINGZUO {name:"天秤座" }) RETURN star,xingzuowith,xingzuo
MATCH (star:Star {id:"2012"}) CREATE (star)-[birthIn:BIRTHIN]->(place:PLACE {name:"北京" }) RETURN star,birthIn,place
MATCH (star:Star {id:"2012"}) CREATE (star)-[jiguanWith:JIGUANWITH]->(place:PLACE {name:"河北唐山" }) RETURN star,jiguanWith,place
MATCH (star:Star {id:"2012"}) CREATE (star)-[genderWith:GENDERWITH]->(gender:GENDER {name:"女" }) RETURN star,genderWith,gender
MATCH (star:Star {id:"2012"}) CREATE (star)-[birthYear:BIRTHYEAR]->(year:YEAR {name:"1979" }) RETURN star,birthYear,year
MATCH (star:Star {id:"2012"}) CREATE (star)-[birthMouth:BIRTHMOUTH]->(mouth:MOUTH {name:"10" }) RETURN star,birthMouth,mouth
MATCH (star:Star {id:"2012"}) CREATE (star)-[bloodwith:BLOODWITH]->(blood:BLOOD {name:"A" }) RETURN star,bloodwith,blood
MATCH (star:Star {id:"2012"}) CREATE (star)-[hightwith:HIGHTWITH]->(hight:HIGHT {name:"165cm" }) RETURN star,hightwith,hight
MATCH (star:Star {id:"2012"}) CREATE (star)-[countrywith:COUNTRYWITH]->(country:COUNTRY {name:"中国" }) RETURN star,countrywith,country
MATCH (star:Star {id:"2012"}) CREATE (star)-[weightwith:WEIGHTWITH]->(weight:WEIGHT {name:"48kg" }) RETURN star,weightwith,weight
MATCH (star:Star {id:"2012"}) CREATE (star)-[sanweitwith:SANWEIWITH]->(sanwei:SANWEI {name:"83,60,87" }) RETURN star,sanweitwith,sanwei
MATCH (star:Star {id:"2012"}) CREATE (star)-[schoolwith:SCHOOLWITH]->(school:SCHOOL {name:"中国工运学院",major:"公关文秘" }) RETURN star,schoolwith,school
MATCH (star:Star {id:"2012"})
FOREACH (name in ["无人驾驶","海洋天堂","开往春天的地铁","单身男女","十七岁的单车","高海拔之恋Ⅱ",
"搜索","爱情麻辣烫","一生一世","单身男女2","咱们结婚吧",
"君子道","青红","宝贝计划","左右","第三个人","南京!南京!"] |
CREATE (star)-[majorin:MAJORIN]->(movie:MOVIE {name:name}))
MATCH (star:Star {id:"2012"})
FOREACH (name in ["倚天屠龙记","咱们结婚吧","华策版天龙八部","天下第一","非常静距离","准点出击",
"大秦帝国之裂变"] |
CREATE (star)-[majorin:MAJORIN]->(tv:TV {name:name}))
MATCH (star:Star {id:"2012"})-[workas:WORKAS]->(job:JOB)
MATCH (star:Star {id:"2012"})-[xingzuowith:XINGZUOWITH]->(xingzuo:XINGZUO)
MATCH (star:Star {id:"2012"})-[birthIn:BIRTHIN]->(place1:PLACE)
MATCH (star:Star {id:"2012"})-[jiguanWith:JIGUANWITH]->(place2:PLACE)
MATCH (star:Star {id:"2012"})-[genderWith:GENDERWITH]->(gender:GENDER)
MATCH (star:Star {id:"2012"})-[birthYear:BIRTHYEAR]->(year:YEAR)
MATCH (star:Star {id:"2012"})-[birthMouth:BIRTHMOUTH]->(mouth:MOUTH)
MATCH (star:Star {id:"2012"})-[bloodwith:BLOODWITH]->(blood:BLOOD)
MATCH (star:Star {id:"2012"})-[hightwith:HIGHTWITH]->(hight:HIGHT)
MATCH (star:Star {id:"2012"})-[countrywith:COUNTRYWITH]->(country:COUNTRY)
MATCH (star:Star {id:"2012"})-[weightwith:WEIGHTWITH]->(weight:WEIGHT)
MATCH (star:Star {id:"2012"})-[sanweitwith:SANWEIWITH]->(sanwei:SANWEI)
MATCH (star:Star {id:"2012"})-[schoolwith:SCHOOLWITH]->(school:SCHOOL)
MATCH (star:Star {id:"2012"})-[majorin:MAJORIN]->(movie:MOVIE)
MATCH (star:Star {id:"2012"})-[majorin:MAJORIN]->(tv:TV)
return star,workas,job,
xingzuowith,xingzuo,
birthIn,place1,
jiguanWith,place2,
genderWith,gender,
birthYear,year,
birthMouth,mouth,
bloodwith,blood,
hightwith,hight,
countrywith,country,
weightwith,weight,
sanweitwith,sanwei,
schoolwith,school,
majorin,movie,tv