cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

No relationships being stored in catalog from variable-length pattern matching / apoc.path.expand

mike
Graph Buddy

Hi all, I am storing graphs in the catalogue and have an issue when using variable-length matching and it's sophisticated older sister apoc.path.expand...

The dataset is all UK companies and company officers and is very fragmented. There is a wide variety of clusters sizes. I want to be able to expand x hops.

In testing, if I write the relationshipsQuery path long-hand:

(o1:Officer)-[:IS_OFFICER]-(c:Company)-[:IS_OFFICER]-(o2:Officer)

I get the expected results

But if I try either variable-length matching (or apoc.path.expand.. but not shown in this example), using this relationshipQuery - which should be equivalent to the long-hand version (I think?)

MATCH p = (o1:Officer)-[:IS_OFFICER*..2]-(c:Company) WHERE o1.postcode STARTS WITH "BS6 6" UNWIND relationships(p) as rel WITH startNode(rel) as start, endNode(rel) as end RETURN id(start) AS source, id(end) AS target

The node count is the same but no relationships are stored??

Any help feedback very much appreciated,
Cheers,
Mike

1 ACCEPTED SOLUTION

I think the label for c should be Officer rather than Company?

MATCH p = (o1:Officer)-[:IS_OFFICER*..2]-(c:Officer) 
WHERE o1.postcode STARTS WITH "BS6 6" 
UNWIND relationships(p) as rel 
WITH startNode(rel) as start, endNode(rel) as end 
RETURN id(start) AS source, id(end) AS target

View solution in original post

2 REPLIES 2

I think the label for c should be Officer rather than Company?

MATCH p = (o1:Officer)-[:IS_OFFICER*..2]-(c:Officer) 
WHERE o1.postcode STARTS WITH "BS6 6" 
UNWIND relationships(p) as rel 
WITH startNode(rel) as start, endNode(rel) as end 
RETURN id(start) AS source, id(end) AS target

mike
Graph Buddy

Of course!! Thanks Mark