cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Get all existing relationships between a set of nodes

Hello!
I have a set of nodes that I get with:

Match (p:Person) WHERE p.Netzwerke = 7 CALL apoc.neighbors.tohop(p,"connect",2) yield node return node

In the Neo4J Browser it also shows me all the existing relationships between that nodes but I can only yield the nodes without this relationships. Is there a way to get the list of nodes with all the existing relationships between them? I would like to export that list of nodes with their relationships to Gephi. I am thankful for every idea!

Best regards,
Lars

3 REPLIES 3

apoc.algo.cover() is a procedure you can use to get all the relationships that exist between a collection of nodes. This is similar to what the browser does...after it gets back nodes from the original query it sends out a second query to get all the relationships between those nodes. There's a checkbox you can use to toggle that on or off in the browser preferences.

Here's how you would do this in the query:

Match (p:Person) 
WHERE p.Netzwerke = 7 
CALL apoc.neighbors.tohop(p,"connect",2) yield node 
WITH collect(node) as nodes
CALL apoc.algo.cover(nodes) YIELD rel
WITH nodes, collect(rel) as rels
RETURN nodes, rels

I most certainly did not know about this.

Thank for i have learned something new.

Worked perfectly! Thank you very much!