Nodes:graph data records 结点 用"()"java
Relationships : connect nodes 关系 用"[]"node
properties : named data values 属性 (node和relationships都有属性) 用"{}"maven
labels :表名(不须要提早建立)ide
语法官网 https://neo4j.com/docs/developer-manual/current/cypher/syntax/parameters/code
CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'}) CREATE (Keanu:Person {name:'Keanu Reeves', born:1964})
create (Anders:test {name:"Anders"}) create (Ceasar:test {name:"Ceasar"}) create (Bossman:test {name:"Bossman"}) create (Emil:test {name:"Emil"}) create (David:test {name:"David"}) CREATE (Anders)-[:KNOWS]->(Bossman), (Anders)-[:BLOCKS]->(Ceasar), (Ceasar)-[:KNOWS]->(Emil), (Bossman)-[:KNOWS]->(Emil), (Bossman)-[:BLOCKS]->(David), (Anders)<-[:KNOWS]-(David)
CREATE (Anders:test {name:"Anders"})-[:KNOWS]->(Bossman :test {name:"Bossman"}), (Anders:test {name:"Anders"})-[:BLOCKS]->(Ceasar :test {name:"Ceasar"}), (Ceasar:test {name:"Ceasar"})-[:KNOWS]->(Emil :test {name:"Emil"}), (Bossman:test {name:"Bossman"})-[:KNOWS]->(Emil :test {name:"Emil"}), (Bossman:test {name:"Bossman"})-[:BLOCKS]->(David :test {name:"David"}), (Anders:test {name:"Anders"})<-[:KNOWS]-(David :test {name:"David"})
删除全部的节点,谨慎使用 MATCH (n:test) DETACH DELETE n 删除节点及关系 MATCH (n)-[r]-() DELETE n,r 单纯删除全部节点: match (n) delete n
match (n:Greeting) return count(n)
match (a:job) WHERE NOT ((a)--()) RETURN a.job_id 或 match (a:job) WHERE NOT ((a)-[]-()) RETURN a.job_id match (a:job) WHERE NOT ((a)<-[]-()) RETURN a.job_id
MATCH (a:Person) where a.name starts with "T" return a.name ;
MATCH (a:Person)-[:ACTED_IN]->(m)<-[:DIRECTED]-(d) where a.name="Tom Hanks" RETURN a,m,d LIMIT 10; match (a:job)-[]->(b:job) where b.job_id="job_scheduling" RETURN a,b
查询直接指向job_scheduling 节点的节点个数图片
match p=(a:job)-[:denp]->(b:job) where b.job_id="job_scheduling" RETURN count(p) 等价于 match p=(a:job)-[:denp]->(b:job {job_id:"job_scheduling"}) RETURN a,b
match p= (j1:job)-[:denp*2..]->(j2:job) with collect(distinct j1.job_id ) as lista match (j3:job) with collect(distinct j3.job_id ) as listb ,lista with FILTER( n IN listb WHERE NOT n IN lista ) as listc unwind listc as c RETURN c match p= (j1:JOB0317)-[:denp*2..]->(j2:JOB0317) with collect(distinct j1.job_id ) as lista match (j3:JOB0317) with collect(distinct j3.job_id ) as listb ,lista with FILTER( n IN listb WHERE NOT n IN lista ) as listc unwind filter(x in listc where x starts with "stg") as c return c
介绍:(1)withip
(2)unwind:UNWIND会将大量的数据(高达10k或者50k条)[一个数据集合collect]分散成一行一行的。好比:
UNWIND[1,2,3] AS x RETURN x WITH [1,1,2,2] AS coll UNWIND coll AS x WITH DISTINCT x RETURN collect(x) AS SET
match (j:job) where j.job_id=~"stg.*" with j.job_id as jid match p=(j1:job{job_id:jid})-[:denp*]->(j2:job {job_id:"job_scheduling"}) unwind nodes(p) as nds with sum(nds.duration) as sum , length(p) as len , nodes(p) as ns order by sum desc return sum/3600 ,len ,extract(n IN ns | n.job_id ) as ids limit 10 match (j:job) where j.job_id=~"stg.*" with j.job_id as jid match p=(j1:job{job_id:jid})-[:denp*]->(j2:job {job_id:"job_scheduling"}) unwind nodes(p) as nds with sum(nds.duration) as sum , length(p) as len , nodes(p) as ns order by sum desc return sum/3600 ,len ,ns limit 10
match (j:job) where j.job_id=~"stg.*" with j.job_id as jid match p=(j1:job{job_id:jid})-[:denp*]->(j2:job) unwind nodes(p) as nds with sum(nds.duration) as sum , length(p) as len , nodes(p) as ns order by len desc return sum/3600 ,len ,extract(n IN ns | n.job_id ) as ids limit 10
一、maven依赖get
<dependency> <groupId>org.neo4j.driver</groupId> <artifactId>neo4j-java-driver</artifactId> <version>1.4.4</version> <!--<scope>provided</scope>--> </dependency>
二、it