I am new to Cypher and Neo4j (and Stack Overflow for that matter), so hopefully this question has an easy answer. I have spent hours reading the documentation and Googling, but found nothing exactly on point to answer this question.
Apparently I need more reputation to post images, so I will do my best with text.
I can find the path from one node to another like such:
MATCH path = (a {name:"a"})-[*]-(x {name:"x"})
RETURN extract(r IN nodes(path) | r);
Which could return something like the following two paths:
(a)-[:RED]->(b)<-[:BLUE]-(c)-[:RED]->(f)<-[:RED]-(g)-[:BLUE]->(h)<-[:RED]-(x)
(z)-[:RED]->(h)<-[:RED]-(x)
So far so good. There are, of course, lots of other relationships and nodes in the database that connect to these nodes, but this is the right path.
I need to find the one node along the path that has two RED relationships coming into it like so:
-[:RED]->(findme)<-[:RED]-
In the two path examples above, findme = (f) and (h).
Note: There will be lots of matches in the database, but I only want the one in the path (should only be one). Also, there could be many nodes and different relationships in the path, or as few as only 3 nodes each connected by the RED relationship.
I tried matching using:
MATCH (a)-[*]-(b)-[:RED]->(findme)<-[:RED]-(c)-[*]-(x) RETURN findme;
which works as long as there are at least 5 nodes, but won't work for 3 nodes.
How can I find this pattern match within a path?
RETURN nodes(path)
directly. – jjaderberg