Time traversal path query

We are storing timestamp at edge level and node level.
What are the best practices or recommendations to traverse through edges/nodes and display nodes in the same order by timestamp. Or display path of node order by timestamp in ascending order.


Are the timestamps on the path ever out of order? Why would that be -- what is the domain of your data?

What have you tried so far with Cypher? You can match paths in cypher like so:

MATCH p=(a:A)-[:REL*]->(b:B)

You can also destructure paths and work through every node by using FOREACH and the nodes function.

In logistics domain, we have multiple "State" nodes hanging off of "Trip" node. There is 1:M relationship between Trip and State nodes. Currently there are around 1000 nodes hanging off of Trip node but we need to order those State nodes in an order by timestamp (timestamp is stored on edge between Trip->State as well as State node iteself) to know status at a certain point of time.

Tried "order by" in cypher but did not get expected result.

Please let us know best practices and your recommendation.


Please post what cypher you've done so far, what results it returned, and what you want the results to be. This lets us be much more precise.

The best practices are what I mentioned in my last email -- match paths, and then destructure paths as needed. But this could change depending on your needed output format and what your data model looks like.

We have established time traversal path using below cypher which created edges between the nodes in database.

MERGE (elem:trip_1)-[r:HAS_STATE_OF]->(list:state)
WITH list ORDER BY list.statetime ASC
WITH COLLECT(list) AS lists
FOREACH (n IN RANGE(0, LENGTH(lists)-2) |
FOREACH (prec IN [lists[n]] |
FOREACH (next IN [lists[n+1]] |
MERGE (prec)-[:NEXT]->(next))))

Now we are trying to calculate the distance between any given 2 state nodes using apoc.spatial* functions as nodes have latitude and longitude attributes.

Please let us know your inputs if there are any other recommendations.