Warm tip: This article is reproduced from serverfault.com, please click

neo4j shortest path with common relation property

发布于 2020-11-29 07:22:33

As the picture below shows we have nodes with relations but with different properties. how can I find shortest path between node A and node E with condition that relations in the path should have common property? for example here it only should give THE PATH with property "a" from node A to node B because a here is common.

unique labeled path

Edit I want to find shortest path between node a and e based on available relations between a and next node (here relation properties are a, b and c) how can I find shortest path between a and e in which relations property is same(here property a) for example it should return only the path with property a (and the path would be a>b>d>e)

Questioner
M.B
Viewed
0
M.B 2020-11-30 19:08:16

I found the answer and the answer was:

Match (a:node)-[r1]->()
with collect(r1.property) as m
MATCH p=shortestPath( (a:node)-[:r1*]->(e:node) ) 

AND ALL(x in relationships(p) WHERE x.propery in m)
RETURN p