查询
查询全库:
MATCH (n) RETURN n
match (n)-[r]-(m) return n,r,m
查询某一个图的全部信息:
MATCH (n:Subject1) RETURN n
match (n:Subject1)-[r]-(m) return n,r,m
按属性id查询neo4j某一图的节点的属性值:
MATCH (a:Subject3) WHERE a.ID3 = 30001
RETURN a.ID3 AS name, a.title AS title
模糊查询:
match (n:coronavirus) where n.title=~'治疗.*' return n
match(emp:coronavirus) where emp.title =~'.*治疗.*' return emp
MATCH (emp:newGastricCancer)-[r]-(n) WHERE emp.title =~'.*临床表现.*' return emp,r,n
查找两个节点之间关系的最短路径:
MATCH n=allshortestPaths((a:gastricCancer{title:"胃恶性肿瘤"})-[*]-(b:gastricCancer{title:"纤维内窥镜检查"})) return n
根据id 查询属性信息:
MATCH (n:coronavirus) where id(n)=17 RETURN n.title
MATCH (n:coronavirus)-[r]-(m) WHERE id(n) = 17 return n.describe ,r,m
新增
创建节点
create (n:coronavirus{coronavirus_nodeId: 70001, level: 1,title: '就诊科室'}) return n;
create (n:coronavirus{coronavirus_nodeId: 710001, level: 2,title: '发热门诊'}) return n;
create (n:coronavirus{coronavirus_nodeId: 720001, level: 2,title: '感染科'}) return n;
create (n:coronavirus{coronavirus_nodeId: 730001, level: 2,title: '重症监护室'}) return n;
创建关系:
match (n:coronavirus{coronavirus_nodeId: 10001}),(m:coronavirus{coronavirus_nodeId: 70001}) create (n)-[r:就医]->(m) return r;
match (n:coronavirus{coronavirus_nodeId: 70001}),(m:coronavirus{coronavirus_nodeId: 710001}) create (n)-[r:就诊科室]->(m) return r;
match (n:coronavirus{coronavirus_nodeId: 70001}),(m:coronavirus{coronavirus_nodeId: 720001}) create (n)-[r:就诊科室]->(m) return r;
match (n:coronavirus{coronavirus_nodeId: 70001}),(m:coronavirus{coronavirus_nodeId: 730001}) create (n)-[r:就诊科室]->(m) return r;
修改
根据名称重命名标签名:
MATCH (n:Subject14)
REMOVE n:Subject14
SET n:病状诱因
根据id 修改属性:
MATCH (r:pancreaticCancer)
WHERE id(r) = 472
SET r.level= 5
删除
清空所有数据
MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r
删除某一个图的节点。
MATCH (n:ophlogosis) DELETE n
删除某一个图节点和关系
MATCH (n:pancreaticCancer)-[r]-() DELETE n,r
使用Match和Where可以按ID删除关系.
Match (n:ophlogosis)-[r]-() Where ID(r)=401 Delete r
根据id 删除属性
MATCH (n) where id(n)=17 REMOVE n.test