0
votes

I have a graph as below. The purple color nodes(11376 & 11394) are my root nodes i.e., my graph starts from there.

Now I wanted to write a cypher query such a way that i should get complete path for node 11376 i.e., from start node to end node (purple to yellow) . Also when i say node 11376 I should not get other node 11394. How can i do it.

I tried the below query but did not get the desired output:

 match (hh{id:'11376'})-[*0..2]-(n) return n;

It is giving other node as well i.e., 11394

Below is the neo4j grapg:

My graph

So if i write cypher match query for node 11376, i should get the complete below path , as below. enter image description here

How can i do it ?

Thanks

2

2 Answers

1
votes

By using your the label types of your yellow nodes, write the query as:

match path = (hh{id:'11376'})-[*0..3]-(n:YELLOW_NODE_LABEL_TYPE_HERE)
return path;

That will return all paths that traverse 3 hops or less from (node {id:'11376'}) to any nodes who have the label type you've assigned to your yellow nodes. The paths through the second purple node will not be included in your result because it will take greater than three hops to get to another yellow node through both purple nodes.

0
votes

Well you know that there will be minimum 3 hops so you can specify it in your query :

MATCH p=(hh {id:11376})-[r*3]-(n)) RETURN p

By the way without having a label for the yellow nodes you can not restrict that the path must end with a yellow node so with the above query you might have some extra paths