How to set weights for infered edges?

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?

Ah, you're right! There was a typo in my labels, thank you.

Related to my question: is it possible to return a "view" of the resulting edges in the browser without actually saving the new edges to the database?

Hi Rogie,

The view you are looking for might be a good use case for virtual relationships with the apoc library. http://neo4j-contrib.github.io/neo4j-apoc-procedures/3.5/virtual/virtual-nodes-rels/

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;

Best wishes,
Nathan