t3d
t3d

Reputation: 178

Neo4j return nodes indirectly connected to each other with merged relationship

I have a dataset where the following query returns the whole topology.

MATCH (na:node)-[ra:composition]-(ia:interface)-[rb:compound]-(ib:interface)-[rc:composition]-(nb:node)
RETURN na,ia,ib,nb
LIMIT 1000

I would like to merge ia and ib into only one relationship so that I will only get nodes connected to each other and not their intermediary interfaces.

Like this:

(na:node)-[r:CONNECTED_TO]-(nb:node)

Anyone know how?

Upvotes: 3

Views: 577

Answers (1)

Ron van Weverwijk
Ron van Weverwijk

Reputation: 547

I'm not completely sure if I correctly understand what you want to do, but shooting from the hip:

MATCH (na:node)-[ra:composition]-(ia:interface)-[rb:compound]-(ib:interface)-[rc:composition]-(nb:node)
WITH na,nb
LIMIT 1000
MERGE (na)-[:CONNECTED_TO]-(nb)
RETURN count(*)

Run this query until count equals 0

Upvotes: 1

Related Questions