The "limit" for cypher query result

70 views
Skip to first unread message

Liping Huang

unread,
Dec 5, 2017, 2:46:31 AM12/5/17
to Neo4j

Usually "limit" used to return the subset of the row





the the graph as a example, the return row will be:


depth     limit   rows


1               4       A B C D
2               4       A C D F

seems the default behavior is return as many as the subset rows, but limit the rows which direct to the root node, but how to return as many as the nodes which link to the root nodes?

Thanks.


Kamal Murthy

unread,
Dec 6, 2017, 3:13:06 PM12/6/17
to Neo4j
Hi Huang,

Try this:

MATCH (r:root)-[]->(d)
RETURN r, d:

-Kamal

Liping Huang

unread,
Dec 7, 2017, 3:32:45 AM12/7/17
to Neo4j
Thanks for the reply, but I really want to return the path so I can transform to the graph structure for visualization.

在 2017年12月7日星期四 UTC+8上午4:13:06,Kamal Murthy写道:

Kamal Murthy

unread,
Dec 7, 2017, 3:44:34 PM12/7/17
to Neo4j
Hi Huang,

Here my solution:

I created your scenario:
CREATE (c1:Company {name: "A"})
CREATE (c2:Company {name: "B"})
CREATE (c3:Company {name: "C"})
CREATE (c4:Company {name: "D"})
CREATE (c5:Company {name: "E"})
CREATE (c6:Company {name: "F"})
CREATE (c7:Company {name: "G"})
CREATE (c8:Company {name: "H"})
CREATE (c1)-[:TO]->(c2)
CREATE (c1)-[:TO]->(c3)
CREATE (c1)-[:TO]->(c4)
CREATE (c3)-[:TO]->(c5)
CREATE (c3)-[:TO]->(c6)
CREATE (c4)-[:TO]->(c7)
CREATE (c4)-[:TO]->(c8);

Query to get your desired result:
//Collect nodes in level 1
MATCH (c:Company {name: "A"})-[:TO]->(d)
WITH COLLECT (d) as nodes, c
UNWIND nodes as v1
//get nodes all connected to level 1 nodes
MATCH (v1)-[:TO]->(e)
RETURN c, v1, e;

Hope this solves your problem.

-Kamal

Liping Huang

unread,
Dec 12, 2017, 10:37:01 PM12/12/17
to Neo4j
Thanks very much.

The cypher like this

MATCH (:Movie{title:'The Matrix'})<-[:ACTED_IN]-(p:Person)
RETURN p, [(p)-[:ACTED_IN]->(m) | m][..3] as movies


resolve my problem,the the return graph really beauty and what I want,  the big problem is actaully I really NOT understand the meaning of  [(p)-[:ACTED_IN]->(m) | m][..3]

在 2017年12月8日星期五 UTC+8上午4:44:34,Kamal Murthy写道:

Michael Hunger

unread,
Dec 13, 2017, 6:04:49 AM12/13/17
to ne...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages