I have the graph model below and am trying to write a Cypher query that finds the shortest path from a Person
to a Skill
that includes at least one instance of the relationship HAS_SKILL
in the path.
In the model
- a
Person
is connected to anotherPerson
via theIS_CONNECTED_TO
relationship - a
Person
is connected to aSkill
viaHAS_SKILL
- a
Skill
is connected to anotherSkill
via theIS_RELATED_TO
relationship
I have come up with the following query, which works but unwraps all the relationships in the path to check that the HAS_SKILL
relationship is one of the relationships.
match (person:Person {id: "48"}), (skill:Skill {id: '10667'}),
path = shortestPath((p)-[*..30]-(s))
WHERE ANY(r in relationships(path) where type(r) = 'HAS_SKILL')
return path;
Is there a more effecient way to do this?
I have played around with relationship pattern matching in (p)-[*..30]-(s)
but I couldn't get it work in the same way that ANY
in the where clause works?
This is using neo4j 4.1.0.
HAS_SKILL
?? From your graph schema, it seems it's not? – stellasiaSkill
s not viaHAS_SKILL
– user783836