CREATE (n:Person { name: 'Andres', title: 'Developer' }) return n;
CREATE (n:Person { name: 'Vic', title: 'Developer' }) return n;java
CREATE (n:Program { name: 'java', title: 'IT' }) return n;node
CREATE (n:Program { name: 'c', title: 'IT' }) return n;python
CREATE (n:Program { name: 'python', title: 'IT' }) return n;
//建立節點
CREATE (n:Program { name: 'cpp', title: 'IT' }) return n;正則表達式
CREATE (n:Person { name: 'Jly', title: 'Developer' , age : 16 }) return n;api
CREATE (n:Person { name: 'Zd', title: 'Developer' , age : 18 }) return n;函數
//建立關係 create unique
match(n:Person{name:"Vic"}),(m:Program{name:"c"}) create (n)-[r:hasAbility]->(m) return r;性能
match(n:Person{name:"Vic"}),(m:Program{name:"java"}) create (n)-[r:hasAbility]->(m) return r;測試
match(n:Person{name:"Vic"}),(m:Program{name:"cpp"}) create (n)-[r:hasAbility]->(m) return r;索引
match(n:Person{name:"Andres"}),(m:Program{name:"python"}) create (n)-[r:hasAbility]->(m) return r;ip
match(n:Person{name:"Vic"}),(m:Person{name:"Andres"}) create (n)-[r:Friend]->(m) return r;
match(n:Person{name:"Vic"}),(m:Person{name:"Andres"}) create (n)<-[r:Friend]-(m) return r;
match(n:Person{name:"Jly"}),(m:Person{name:"Zd"}) create (n)<-[r:Friend]-(m) return r;
match(n:Person{name:"Andres"}),(m:Person{name:"Zd"}) create (n)<-[r:Friend]-(m) return r;
//刪除
match(a:Person{name:"Andres"})-[r:Friend]-(a) delete r ;
//更新
match(a:Person{name:"Andres"}) set a.hair='red' ;
match(:Person{name:"Andres"})-[:Friend]->(b) return b ;
//匿名關係
match(:Person{name:"Andres"})-[:Friend]->(b),(b)-[:hasAbility]->(c) return c ;
//匿名節點()
match(n:Person{name:"Vic"}),(n)-[r:Friend]->() return r;
match (n:Person { name: 'Andres'})
return n;
//條件用
match(n:Person{name:"Vic"}),(m:Person{name:"Andres"}),(n)-[r:Friend]->(m) return r;
// 逗號 隔開 表明AND 以下 定義了兩個c
match(:Person{name:"Andres"})-[:Friend]->(b),(b)-[:hasAbility]->(c),(c:Program{name:"cpp"}) return c ;
//where 語句
match (a:Person{name:"Andres"})-[:Friend]->(b),(b)-[:hasAbility]->(c) where not (a)-[:hasAbility]->(c) return c ;
match(:Person{name:"Andres"})-[:Friend]->(b),(b)-[:hasAbility]->(c),(c:Program{name:"cpp"}) return c ;
match (n:Person { title: 'Developer'})
return n;
//匹配全部節點
match(n)
return n;
//根據編號查詢 測試這裏的start不能省略
start n=node(0,20)
return n;
//distinct 去重 ,貌似沒看到重複
start n=node(0,20)
match (n)-[:hasAbility]->(c)
return c;
//建立索引
CREATE INDEX ON :Person(name);
CREATE INDEX ON :Program(name);
//索引查找
MATCH (p:Person {name: 'Andres'})
RETURN p;
match (p:Person)
where p.title='Developer'
return p;
//能夠返回倆值
match (p:Person),(n:Person)
where p.name='Zd'
return p,n;
//order by limit skip
match (p:Person)
where p.title='Developer'
return p
order by p.name desc
skip 1
limit 2
//支持正則表達式匹配 =~/.*@qq.com/
//has()函數 Unknown function 'has' 實測:不可用
match (p:Person)
where has(p.age)
return p;
//複雜查詢性能 Cypher不如 java api
//查詢 Friend關係全部節點 支持count函數,sum avg max min
start n=node(*)
match (n)-[:Friend]-()
return n,count(*)
//關係標識符TYPE 結果以關係類型分組
start n=node(*)
match (n)-[rel]-()
return TYPE(rel),count(*)
//Andres與Jly 爲好友關係(1至3層擴線)的節點 返回的是整個路徑
MATCH (p:Person {name: 'Vic'}),(n:Person {name: 'Jly'}),k=(p)-[:Friend*1..3]-(n)
RETURN k;
//ALL 每個單個元素都匹配 實測不支持
//cypher 1.8 使用的版本
cypher 1.8 match (p:Person)
where ALL(
user in NODES(p)
where user.title='Developer'
)
return p
//管道語句 with 保存中間數據結果 start n=node(*) match (n)-[rel]-() with TYPE(rel) as type,count(*) as count where count>8 return type,count