创建的图
语句
-- 清空
match (n1)-[r1]-(n2) delete n1,n2,r1;
--查
match (n1)-[r1]->(n2) RETURN n1,r1,n2;
MATCH (a:label1),(m:label2) OPTIONAL
MATCH (a)-[r1]-(), (m)-[r2]-() DELETE a,r1,m,r2;
CREATE (n:Person{ name: 'lzl',bornYear: 1974});
match (n) return n;
match (n:Person) where n.name='lzl' return n;
match(n{name:'lzl'}) return n;
match(n) where n.born<1999 return n;
--导入
LOAD csv FROM 'http://we-yun.com/neo4jguide/movie.csv' AS line
CREATE (:Movie{title:line[0],relased:line[1],tagline:line[2]})
RETURN line;
-- a friend of a friend
CREATE (wei:student:male{name:'wwl'}),
(jin:student:male{name:'jj'}),
(liu:student:male{name:'xld'}),
(wei)-[:Friend{time:'2014-9'}]->(jin),
(jin)-[:Friend{time:'2014-9'}]->(liu);
match (wei:student{name:'wwl'})-[:Friend]->()-[:Friend]->(fof)
RETURN fof.name AS fofname;
-- ppt KNOWS
create (a:Person{name:'jim'})-[:KNOWS]->
(b:Person{name:'lan'})-[:KNOWS]->
(c:Person{name:'Emil'}),
(a)-[:KNOWS]->(c);
--===================ppt test0=======================
CREATE (:Person{name:'lan'})-[:EMPLOYMENT]->
(job:Job{start:'2011-01-05'})-[:EMPLOYER]->
(:Company{name:'Neo'}),
(job)-[:ROLE]->(:Role{name:'engineer'});
MATCH (p:Person),(j:Job),(r:Role),(c:Company) OPTIONAL
MATCH (p)-[r1]-(), (j)-[r2]-(), (r)-[r3]-(),(c)-[r4]-()
DELETE r1,r2,r3,r4,p,j,r,c;
--===================ppt test1=========================
CREATE (:Actor{name:'William Hartnell'})-[:PERFORMED_IN]->
(performance:Performance{year:1964})-[:FOR]->
(:Story{title:'The Sensorties'}),
(performance)-[:PLAYED]->(:Role{name:'The Doctor'});
--====================ppt test2==========================
CREATE (:Person:man{name:'Lan'})-[:SENT]->
(email:Email{content:'...'})-[:TO]->
(:Person{name:'Jim'}),
(email)-[:CC]->(:Person{name:'Alistair'});
--====================ppt test3==========================
CREATE (:Person {name: 'Alistair'})-[:WROTE]->
(review :Review {test: '…'})-[:OF]->
(:Film{title: '…'}),
(review)- [:PUBLISHED_IN]->
(:Publishion{title: '…'};
-- 清空
match (n1)-[r1]-(n2) delete n1,n2,r1;
--查
match (n1)-[r1]->(n2) RETURN n1,r1,n2;
CREATE (a:Person{name:'aa',age:18})-[:Friend]->
(b:Person{name:'bb',age:19})-[:Friend]->
(c:Person{name:'cc',age:20}),
(a)-[:Friend]->
(d:Person{name:'dd',age:21})-[:Friend]->
(e:Person{name:'ee',age:22});
match (a:Person)-[:Friend]->()-[:Friend]->(fof)
WHERE a.age=18
RETURN fof.name AS name;
match (a:Person)-[:Friend]->()-[:Friend]->(fof)
WHERE id(a)=23
RETURN fof.name AS name;
CREATE (a:Person{name:'aa'})-[:Friend]->
(b:Person{name:'bb'})-[:Friend]->
(c:Person{name:'cc'}),
(b)-[:Friend]->
(d:Person{name:'dd'})
--MERGE
MERGE (a:Person:male {name: 'wwl'});
MERGE (b:female:teacher {name: 'dxf'});
MATCH (a:Person {name: 'wwl'}),(b:female{name: 'dxf'})
MERGE (a)-[:KNOWS]->(b);
MERGE (n:student{name: 'wwl'})
ON CREATE SET n.created = timestamp();
Match (a {name: 'wwl'}),(c {name: 'dxf'})
MERGE (a)-[:Friend{rels:3}]->(c);
MERGE (wei1:Person {name:'wei1'})
ON CREATE SET wei1.created=timestamp() --不存在则创建
ON match SET wei1.lastSeen=timestamp() --存在则创建
RETURN wei1.name,wei1.created,wei1.lastSeen;
--SET
UNWIND [{age:30},{addr: 'bj'}] AS prop
MERGE (n:Person {name: 'a'})
SET n += prop;
MERGE (n:Person {name: 'a'})
SET n.created = timestamp();
MERGE (n:female:teacher {name: 'dxf'})
SET n:Person;
--remove
MATCH (n) REMOVE n:Person;
MATCH (a {name: 'a'}) REMOVE a.name;
--where
CREATE (n:Person{ name: 'foo',bornYear: 1974}), (m:Person{ name: 'son',bornYear: 1999});
match (n) where n.bornYear>1998 and not n.name='foo' return (n); -- son
match (n) where n.bornYear>1998 or not n.name='foo' return (n); -- son
match (n) where n.bornYear>1998 xor n.name='so1n' return (n); -- son
--foreach
WITH ['a','b','c'] AS col FOREACH (value IN col | CREATE (:Person {name:value}));
--delete
match (n) detach delete n;