Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
513 views
in Technique[技术] by (71.8m points)

graph - Cypher to show relationships of hidden nodes

I’m a total beginner in Cypher and I’m struggling to obtain the result I want.

So I have nodes that all have a property called ??level??. I want to keep only a certain level, but I want to recreate the missing links.

Here is my dataset:

enter image description here

in CSV:

n
"{owner:Team A,name:MySubscription,level:1}"
"{name:Database,level:2}"
"{owner:Team A,name:Service A,level:3}"
"{owner:Team A,name:MyTopic,level:2}"
"{name:Service B,level:3}"
"{name:Service C,level:3}"
"{name:MySecret,level:1}"

I want to keep only the nodes that are level >= 2 but I want to recreate the links like so:

enter image description here

Could you help me create the query that does just this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Not sure it's the better way to do it. But I did found the answer:

MATCH (a:Asset)-[rel]-(b:Asset) WHERE a.level >= 2 AND b.level >= 2 
RETURN a, rel, b

UNION

MATCH (a:Asset) -[:USING]-(:Asset)-[:ATTACHED]-(b:Asset) WHERE a.level >= 2 
AND b.level >= 2
CALL apoc.create.vRelationship(a,'USING',{}, b) YIELD rel
RETURN a, rel, b

UNION

MATCH (a) WHERE NOT (a)--() 
RETURN a, null as rel, null as b;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...