Hi everyone,

I'm new to cypher and I'm trying to run a query on a large graph.

The idea is to match a variable length pattern, but only within a subset of nodes from the full graph. The graph represents all the parts used to construct a set of products, with the components of each product indicated by the 'uses' relation and the hierarchy of construction for a single product indicated by the 'has' relation.

So I wrote this:

MATCH (m:Product {serialnumber:'8352'})-[:uses]->(p:Part)

WITH m,p

MATCH path=(p)<-[r:has]-(nha:Part)<-[:has*]-(anc:Part)

RETURN path

LIMIT 100

But the results look like the second MATCH is finding parent nodes from the whole graph, not only the subset p defined by the first MATCH. I was hoping that the first MATCH could define a subgraph that only includes nodes from a single product.

How can I ensure that the paths returned by the query only inlcude nodes that satisfy the first MATCH?

Many thanks,

Ben