I would like to add edges between nodes of distance 2 apart, and set a weight property according to how many such paths of length 2 exists. I think a query like this is close, but isn't quite right:
Match path=((u1:User)-[:KNOWS]->(:User)-[:KNOWS]->(u2:User))
With u1, u2, Count(path) as weight
Merge (u1)-[e:FILLEDIN]->(u2)
Set e.weight=weight
This doesn't seem to do anything in my graph. What's the best way to do this?
That looks fine to me. You may want to check that you're using the right labels. If you stopped your query early, doing a RETURN on line 2 instead of a WITH, do you get results back?
Match path=((u1:User)-[:KNOWS]->(:User)-[:KNOWS]->(u2:User))
With u1, u2, Count(path) as weight
RETURN u1, u2, apoc.create.vRelationship(u1,'FILLEDIN',{weight:weight},u2) as rel;