Reputation: 380
I have an Neo4j Cypher query I struggling with. What I want is to have all nodes with a given relationship, until it reach a relation with an properties who is below a given number ( < 25). All nodes after that relationship is found should be skipped.
Here a sample of my graph:
and how I would like the result to be (every nodes after relationship IS_OWNER with Share < 25 should be skipped)
I hope someone can show how to write the Cypher query who can give the desired result (picture 2) from the sample graph (picture 1). Every nodes after relationship IS_OWNER with Share < 25 should be skipped.
Upvotes: 2
Views: 618
Reputation: 30397
The ALL() function should work here, letting you specify that all relationships in the path should have Share >= 25, and pruning further expansion otherwise.
Something like this, assuming starting at company C:
MATCH (:Company{name:'C'})-[rels:IS_OWNER*0..]-(companies)
WHERE all(rel in rels WHERE rel.Share >= 25)
RETURN companies
EDIT:
While it seems like using a variable on the variable-length relationship is deprecated in the newer versions of neo4j (I'll double-check on that, doesn't seem like a good decision), here's another way to specify this which gets around the warning:
MATCH p = (:Company{name:'C'})-[:IS_OWNER*0..]-(companies)
WHERE all(rel in relationships(p) WHERE rel.Share >= 25)
RETURN companies
Upvotes: 3