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
1.2k views
in Technique[技术] by (71.8m points)

neo4j - match using variable and create relationship between the results of the same variable

I have this relationship:

enter image description here

and I have built this clause: enter image description here

My point is that I want now to create a relationship between 1 and 2 after this match, so instead of RETURN n.name, I would need something like: CREATE n1 -[A_RELATIONSHIP]- n2

where n1 = "Serving Gateway" and n2 = "eNode-B".

Practically saying that if those two of the same Label (NetworkFunction) match in this case (as they are both related through another node with a different label but a send or receive relationship), create a relationship called "X" between them

How can I achieve that?


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

1 Answer

0 votes
by (71.8m points)

You can collect all network functions that has a send or receive relationship with mobility management. Then for each network pairs, create that relationship (A_RELATIONSHIP). Note that I used an APOC function (apoc.coll.combinations) so ensure that this function is installed.

MATCH (n:NetworkFunction)
WHERE size((n)-[:SENDS|:RECEIVES]-(:MobilityManagement)) > 0
WITH collect(n) as allNetworkFunctions
UNWIND apoc.coll.combinations(allNetworkFunctions, 2) as network
WITH network[0] as first, network[1] as second
MERGE (first)-[:A_RELATIONSHIP]-(second)

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

2.1m questions

2.1m answers

60 comments

57.0k users

...