All shortest paths between a set of nodes

24 views
Skip to first unread message

Liping Huang

unread,
Dec 11, 2017, 5:27:42 AM12/11/17
to Neo4j

Hi there,


but seems this is satisfy for the certain Label, for example "Entity" in the example cypher query.

But how to use this for multiple labels?


MATCH (n:Entity) where n.name IN {IDS}
WITH collect(n) as nodes
UNWIND nodes as n
UNWIND nodes as m
WITH * WHERE id(n) < id(m)
MATCH path = allShortestPaths( (n)-[*..4]-(m) )
RETURN path

where I need to pass the IDS parameters with different labels

Thanks in advanced.

Michael Hunger

unread,
Dec 11, 2017, 8:48:36 PM12/11/17
to ne...@googlegroups.com
Just do two matches and collect and unwind the first one after you did the 2nd one.

MATCH (n:Entity) where n.name IN {IDS}
WITH collect(n) as nodes
MATCH (m:Entity2) where m.name IN {IDS2}
UNWIND nodes as n

WITH * WHERE id(n) < id(m)
MATCH path = allShortestPaths( (n)-[*..4]-(m) )
RETURN path

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Liping Huang

unread,
Dec 12, 2017, 10:13:23 PM12/12/17
to Neo4j
Yes, thanks for much.

在 2017年12月12日星期二 UTC+8上午9:48:36,Michael Hunger写道:
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages