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