Neo4j 常用查询命令

1、删除节点标记

MATCH (n {})

REMOVE n:Database

RETURN n



MATCH (n { name: '*' })

DETACH DELETE n


2、删除关系类型

MATCH (n { name: 'Andres' })

DETACH DELETE n


3、删除所有节点和关系


MATCH (n)

DETACH DELETE n



CREATE (w1:WeiWen { name: 'W1-syy'})

CREATE (w2:WeiWen { name: 'W2-lyy'})

CREATE (w3:WeiWen { name: 'W3-gzr'})

CREATE (w4:WeiWen { name: 'W4-lxm'})

CREATE (w5:WeiWen { name: 'W5-zjl'})

CREATE (w6:WeiWen { name: 'W6-zjj'})

CREATE (w1:WeiWen)-[:Call { number: 5, name:'维稳' }]->(w2:WeiWen);

CREATE (w2)-[:Call { number: 5, name:'维稳' }]->(w4)

CREATE (w3)-[:Call { number: 1, name:'维稳' }]->(w4)

CREATE (w5)-[:Call { number: 1, name:'维稳' }]->(w2)

CREATE (w6)-[:Call { number: 1, name:'维稳' }]->(w1)




MATCH (a:WeiWen),(b:WeiWen) WHERE a.name = 'W1-sy' AND b.name = 'W5-zjl'

 CREATE (a)-[r:Call]->(b)

RETURN



MATCH (a:WeiWen),(b:WeiWen) WHERE a.name='W5-zjl' and b.name='W4-lxm'

 MERGE (a)-[r:Call]->(b)

return r;




CREATE (s1:SheKong { name: 'S1-syy'})

CREATE (s2:SheKong { name: 'S2-lyy'})

CREATE (s3:SheKong { name: 'S3-gzr'})

CREATE (s4:SheKong { name: 'S4-lxm'})

CREATE (s5:SheKong { name: 'S5-zjl'})

CREATE (s6:SheKong { name: 'S6-zjj'})

CREATE (s1)-[:Call { number: 5, name:'涉恐' }]->(s2)

CREATE (s1)-[:Call { number: 5, name:'涉恐' }]->(s3)

CREATE (s1)-[:Call { number: 5, name:'涉恐' }]->(s5)

CREATE (s2)-[:Call { number: 5, name:'涉恐' }]->(s4)

CREATE (s3)-[:Call { number: 1, name:'涉恐' }]->(s4)

CREATE (s5)-[:Call { number: 1, name:'涉恐' }]->(s2)

CREATE (s6)-[:Call { number: 1, name:'涉恐' }]->(s1)



4、java 链接 neo4j
https://neo4j.com/developer/graph-db-vs-rdbms/



5、新增节点 

CREATE (:ContactMobiles {mobile:'123331'});

CREATE (:MemberIds {memberId:'12312'});



6、新增两个节点之间关系


MATCH (a:ContactMobiles),(b:MemberIds)

WHERE a.mobile='' and b.memberId=''

CREATE (a)-[r:CONTACTMOBILE_AND_MEMBERID]->(b)

return r;



7、查询三层展示

MATCH (n)-[r*1..3]-(m) WHERE id(n) IN [501] RETURN n, r, m
MATCH (n)-[r*3]-(m) RETURN n, r, m
8、统计边数量
MATCH p=()-[r:WeiWen]->() RETURN count(p)
9、搜索两个点的关系
MATCH p=(:WeiWen { name: '12333' })-->(:WeiWen{name:'12313'}) RETURN p

评论