0
votes

I have 5 nodes,1,2,3,4,5
the relationship between 5 nodes as below,

1-->2
2-->3
1-->3
2-->4
3-->5
4-->5

online model http://console.neo4j.org/r/8h0c91
use below cypher query to get one level connection nodes

match (n:Person{name:"1"})-[r]-(m:Person) return n,m,r

result:

n                        r                          m
(20:Person {name:"1"})  []  (20:Person {name:"1"})
(20:Person {name:"1"})  [(20)-[21:Follow]->(22)]    (22:Person {name:"3"})
(20:Person {name:"1"})  [(20)-[20:Follow]->(21)]    (21:Person {name:"2"})

which only can get the relationship between 1-->2 and 1-->3,cannot get 2-->3.
use below cypher query y to get sencond level connection nodes.

match (n:Person{name:"1"})-[r:Follow*0..2]-(m:Person) return n,m,r

result:

n   m   r
(0:Person {name:"1"})   (0:Person {name:"1"})   []
(0:Person {name:"1"})   (1:Person {name:"2"})   [(0)-[0:Follow]->(1)]
(0:Person {name:"1"})   (2:Person {name:"3"})   [(0)-[0:Follow]->(1), (1)-[2:Follow]->(2)]
(0:Person {name:"1"})   (3:Person {name:"4"})   [(0)-[0:Follow]->(1), (1)-[3:Follow]->(3)]
(0:Person {name:"1"})   (2:Person {name:"3"})   [(0)-[1:Follow]->(2)]
(0:Person {name:"1"})   (1:Person {name:"2"})   [(0)-[1:Follow]->(2), (1)-[2:Follow]->(2)]
(0:Person {name:"1"})   (4:Person {name:"5"})   [(0)-[1:Follow]->(2), (2)-[4:Follow]->(4)]

i cannot get the relationship of 4-->5 and 2-->3.
my question is how to get all nodes and relationship between all neo4j nodes.

2
I think you need to clarify exactly what kind of results you're after. Are you looking for a query to get you all the nodes and relationships in your database (in which case Dave Bennett's answer should work, though if you want it for all nodes regardless of label you can drop the :Person label from that query), or are you looking for all reachable nodes from a starting node (and optionally all relationships between them?)InverseFalcon
@InverseFalcon Of course it is the specified condition,this is a scene ,not all of my data.looking for all reachable nodes from a starting node (and optionally all relationships between them?) bagde

2 Answers

0
votes

You could just exclude the name match and add the direction of the relationship and it will return all three.

MATCH (n:Person)-[r]->(m:Person) 
RETURN n,m,r
0
votes

From your comments, you're looking for 'all reachable nodes from a starting node (and optionally all relationships between them)'

In this case, the path expander procedures in APOC Procedures should have what you want:

MATCH (n:Person{name:"1"})
CALL apoc.path.subgraphAll(n, {maxLevel:2}) YIELD nodes, relationships
RETURN nodes, relationships

Edited above to add an upper bound on the traversals.