1
votes

My Schema is like A->B->C->D there are N no of relations in between A to B & B to C and so on but there is one common relation "COMMON" is in between A,B,C,D. Using my "COMMON" relation I want to get all other relation between given two nodes. for eg. get me all relation between A to C

Match path = (a)-[:COMMON*]-(c)
RETURN rels(path);
Above query will get me all nodes in between A to C but it won't return relations in between nodes.

So here what I'm want is to filter the data with COMMON relation first then get all other relations in between A and C. Is there any way to write this query with OR or AND condition?

1

1 Answers

0
votes

Try this:

Match path = (a)-[:COMMON*]-(c)
WITH distinct a,c
MATCH path2 = (a)-[*]-(c)
RETURN rels(path2);

to be more efficient, you might use

MATCH path2 = allShortestPaths((a)-[*]-(c))

or

Match path = (a)-[:COMMON*]-(c)
WITH distinct a,c, min(length(path)) as len
MATCH path2 = (a)-[*]-(c)
WHERE length(path2) <= len
RETURN rels(path2);

Unfortunately this is not possible (yet):

Match path = (a)-[:COMMON*]-(c)
WITH distinct a,c, min(length(path)) as len
MATCH path2 = (a)-[*..len]-(c)
RETURN rels(path2);