Cypher recursive query

948 views
Skip to first unread message

lazyprogrammer

unread,
Jan 9, 2012, 7:55:25 AM1/9/12
to Neo4j
I need to recursively traverse the entire graph db following some
relationship type. Say for example I start from node with Id as 0. I
follow the path with outgoing relationship type "Friends" and get all
direct friends or indirect friends(may be friends of friends, friends
of friends of friends,... so on recursively). I wanted to do it using
Cypher query language. Could anyone please help me out. Thanks in
advance.

Mattias Persson

unread,
Jan 9, 2012, 8:09:43 AM1/9/12
to ne...@googlegroups.com
I'd say

START a=node(0)
MATCH a-[:FRIEND*]->x
RETURN x.name

or for a max depth of 6

START a=node(0)
MATCH a-[:FRIEND*1..6]->x
RETURN x.name

2012/1/9 lazyprogrammer <lazyprogr...@gmail.com>



--
Mattias Persson, [mat...@neotechnology.com]
Hacker, Neo Technology
www.neotechnology.com

Sean Davis

unread,
Jan 9, 2012, 8:17:05 AM1/9/12
to ne...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages