Getting relationships from all node's in Neo4j

83 views Asked by At

I am trying to query using Neo4j. I would like to print result of obtaining information while AUTO-COMPLETE is ON in Neo4j. For example, suppose query that creating 3 nodes as shown below.

create (david:Person {name: 'david'}), (mike:Person {name: 'mike'}), (book:Book {title:'book'}), (david)-[:KNOWS]->(mike), (david)-[:WRITE]->(book), (mike)-[:WRITE]->(book)

Here are 2 images:

  • Auto-complete on

  • Auto-complete off

Figure is shown after query, and I would like to obtain all relating node’s relationships based on starting node ('book' node). I used this query as shown below.

match (book:Book)-[r]-(person) return book, r, person

Whether AUTO-COMPLETE is ON or OFF, I expect to obtain all node’s relationships including “David knows Mike”, but system says otherwise.

I studied a lot of Syntax structure at neo4j website, and somehow it is very difficult for me. So, I upload this post to acquire assistance for you.

2

There are 2 answers

0
ys you On BEST ANSWER

Thanks to InverseFalcon, this is my query that works.

MATCH p = (book:Book)-[r]-(person:Person) 
UNWIND nodes(p) as allnodes WITH COLLECT(ID(allnodes)) AS ALLID 
MATCH (a)-[r2]-(b) 
WHERE ID(a) IN ALLID AND ID(b) IN ALLID 
WITH DISTINCT r2 
RETURN startNode(r2), r2, endNode(r2)
1
Frank Pavageau On

You have to return all the data that you need yourself explicitly. It would be bad for Neo4j to automatically return all the relationships for a super node with thousands of relationships for example, as it would mean lots of I/O, possibly for nothing.

MATCH (book:Book)-[r]-(person)-[r2]-()
RETURN book, r, person, collect(r2) AS r2