0
votes

I know there is a node type (a:Source) which will have outgoing edge of type [:RefRel] on some other node (x). I want to get all other paths between (a) and (x) which involve at least one node between them.

Consider my graph is as follows:

enter image description here

The query should return two paths:a-b-c-d and a-b-c-e. The nodes and relationships on these path can be of any type.

Creating graph with cypher:

CREATE (a:Source)-[:RelA]->(b)-[:RelB]->(c)-[:RelC]->(d)
CREATE (c)-[:RelD]->(e)
CREATE (a)-[:RefRel]->(d)
CREATE (a)-[:RefRel]->(e)

I wrote query as follows:

MATCH (a:Source)-[:RefRel]-(b)
MATCH path=(a)-[*2..]-(b)      //2.. because that means at least one node on the path
RETURN path

But it returned whole graph. When I checked the rows, it returned a lot of them due to cycles in the graph.

So included the filter in the query as follows:

MATCH (a:Source)-[:RefRel]-(b)
MATCH path=(a)-[c*2..]-(b)
WHERE filter(rel IN c WHERE rel.name<>"RefRel")
RETURN path

But then it returned nothing. Whats wrong here?

1

1 Answers

1
votes

None of the relationships you created have a "name" property. Relationships have types, and this is not a property. You want to use

type(rel) <> "RefRel"

Also, on your WHERE, it may be better to use ALL() instead of FILTER().