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.

Breadth First Search Cypher Syntax Not Quite Right?

Hi all, I am using apoc procedures to perform a breadth first search but I think I have not quite gotten the syntax right.

I have my database of dependencies loaded and as an example if I execute this cypher

match (n:Node)-[:Depends_On]->(e:Node) where n.name = "BankAccount" return n, e
I get my expected results that shows my everything that is dependent on 'BankAccount'

3X_3_b_3bc20e1db9acf3f6b3d6b63f9e2395e9006e6989.png

Now I am trying to execute a breadth first search and I want to start at 'BankAccount' and get all the immediate dependencies on 'BankAccount' AND I then want to get ALL of the dependents dependencies as well until there are no more dependencies.

I have managed to come up with this cypher so far

MATCH (n:Node)
WHERE n.name = 'BankAccount'
CALL apoc.path.expandConfig(n,{relationshipFilter:"Depends_On",maxLevel:1,uniqueness:"NODE_GLOBAL"}) YIELD path
WITH n, RELATIONSHIPS(path) as r, LAST(NODES(path)) as es
WHERE es:Node
RETURN n,es,r

but this is not returning the results as I might have expected, I am actually getting the following

I am maybe misunderstanding something but this doesn't look right to me as the relationship arrows all seem to be pointing inwards towards my starting node 'BankAccount'. I am thinking that this should look like my first image but with the addition of all the depenendent dependencies shown also?

Can anyone see what I am doing wrong here?

3 REPLIES 3

ameyasoft
Graph Maven
Try this with no relationship filter:
MATCH (n:Node)
WHERE n.name = 'BankAccount'
CALL apoc.path.expandConfig(n,{maxLevel:1,uniqueness:"NODE_GLOBAL"}) YIELD path
RETURN path

clem
Graph Steward

For those who are following at home, the documentation for version 4.1 seems pretty good with examples (I haven't worked through it yet, so I can't say how good it really is.)

However, the documentation for 4.2 is next to useless, without detailed explanation of the config and no examples, The 4.2 doc needs to be updated:

V 4.2 doc .

At the bottom of the page there is a link to go to next page:
More documentation of apoc.path.expandConfig
and there you can see all the info including examples.