How to write a query to update relationship between nodes of a path of n hops

I have a set of nodes to track trip for trucks with GPS location sequence like
g and g2 gives me list of nodes.

I want to update the relationship between each subsequent nodes with the distance and time between each of the GPSLocation node. The data is present as a point() and datetime() in each of the GPS location nodes.

I am having difficulty to find a way to get the node(0) and node(1) and update the NEXT relationship with property for distance and time between each of the nodes.

I have tried to COLLECT() but do not know how to access the 1st, and 2nd, 2nd and 3rd and so on nodes.
Sorry if this sounds really trivial but it just escapes me.

Hello @vignes_k1 :slight_smile:

You can simplify the problem since you want to update all relationships (I don't know the name of your properties):

MATCH (a:GPSLocation)-[r:NEXT]->(b:GPSLocation)
SET r.distance = distance(a.point, b.point), r.duration = -

If you have a lot to update, you can use: apoc.periodic.iterate() function.


1 Like