I would like to query for the following subgraph in my Neo4J database:
(a)-->(b)-->(c)-->(d)
|
| -->(e)
Note: a, b, c, d, e are attribute values (non-unique values) for each of the nodes. There are thousands for these nodes with similar attribute values (a to e) but they are randomly connected to one another.
How can I write the Cyper query to specifically find the particular subgraph (akin to subgraph isomorphism problem) I seek and return (a)? I've tried the following Cyper query but other subgraphs pop up:
START n1=node:SomeIndex(AttrVal="a")
MATCH n1-[]->n2-[]->n3-[]->n4
WHERE n2.AttrVal="b" AND n3.AttrVal="c" and n4.AttrVal="d"
WITH n1, n2
MATCH n2-[]->n5
WHERE n5.AttrVal="e"
RETURN n1
Am I using the WITH and 2nd MATCH clause wrongly?
Thanks!