对于节点的多节点匹配方案:
// 节点的多类型:“和” 场景
CREATE (n:HOST:SERVICE{name:"test"}) return n;
MATCH (s:SERVICE:INSTANCE) return s;
MATCH (n:HOST) where n:HOST and n:SERVICE return n;
MATCH (n:HOST) where "HOST" in labels(n) and "SERVICE" in labels(n) return n;
MATCH (n:HOST) where ["HOST", "SERVICE"] = labels(n) return n;
// 节点的多类型:“或”场景
MATCH (n:HOST) where n:HOST or n:SERVICE return n;
MATCH (n:HOST) where "HOST" in labels(n) or "SERVICE" in labels(n) return n;
MATCH (n:HOST) where labels(n) in ["HOST", "SERVICE"] return n;
MATCH (n:HOST) where any(l in labels(n) where l in ["HOST", "SERVICE"]) return n;
MATCH (n:HOST) with collect(distinct n) as c1
MATCH (s:SERVICE) with collect(distinct s) + c1 as c2
return c2;
对于关系的多类型查询:
// 关系的多类型:“或” 场景
match p=shortestpath((s:SERVICE{name:"ecms-proc-ext"})-[:ROUTE_TO|ROUTE_WITH*1..5]-(s1:SERVICE{name:"aut"})) return p
MATCH (a:PERSON)-[:LIKE]->(b:ANIMAL), (a)-[:FEED]->(b) return a,b;
MATCH (d:HOST)-[r]-(e:COMPONENT) where type(r) in ['DEPLOY_ON', 'RUN_ON'] return d,e
同多节点类似,不再赘述
对于cypher 语法,建议参考:Neo4j Cypher Refcard 4.4
网友评论