cancel
Showing results for 
Search instead for 
Did you mean: 

Does collapse path make multiple relationships between a pair of nodes if the are multiple paths?

nebuchadnezzar
Node Link

Hi, everyone

I want to try to collapse a path between red nodes in the pic. below

photo_2022-08-09_23-55-08.jpg

 

And get something like that

photo_2022-08-10_01-03-56.jpg

Is it worth trying to make with collapse path, or I get only 1 relationship between each pare of nodes?
Or maybe there exist easier alternatives, I be grateful for suggestions?

 

1 ACCEPTED SOLUTION

Can you share your cypher code.

In GDS usually collapse path should generate 1 relationship per path

and then you might need to use relationship aggregation to result in 1 relationship between a pair of nodes

https://neo4j.com/docs/graph-data-science/current/graph-project/#_parallel_relationships_with_proper...

View solution in original post

2 REPLIES 2

Can you share your cypher code.

In GDS usually collapse path should generate 1 relationship per path

and then you might need to use relationship aggregation to result in 1 relationship between a pair of nodes

https://neo4j.com/docs/graph-data-science/current/graph-project/#_parallel_relationships_with_proper...

Thanks Michael, that's exactly what I wanted to know
and the link will come in handy 🙂

I can share code but I didnt try run GDS collapse path yet because have problems with MATCH

I try that code below and get olny paths through 2 user nodes. (red nodes from pic. are(Community) and yellow nodes are (users) )

MATCH (c1:Community)<-[:MEMBER_OF]-(u1:user)
MATCH (u1:user)-[:FOLLOWING]-(u2:user)
MATCH (u2:user)-[:MEMBER_OF]->(c2:Community)
RETURN c1.name as source, c2.name as target

Also I try that code below and get path through 3 user nodes

MATCH (c1:Community)<-[:MEMBER_OF]-(u1:user)-[]-()-[]-(u2:user)-[:MEMBER_OF]->(c2:Community)
RETURN c1.name as source, c2.name as target

I dont know how to combine so i can get paths through arbitrary number of nodes between red nodes.

 

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.