I have a graph of the form:
(products:Product)-[:in_stock { updated: timestamp }]->(stock_items:StockItem { quantity: q })-[:stored_at]->(locations:Location)
Obviously more to it that that but you get the gist. The stock_item nodes and in_stock edges are added often (locations and products not so much) so for each of these diagrams there'll be many of these relationships. I want to search and filter by the timestamp (milliseconds since Jan1 1970) to only pull the most recent (max value) and return therefore the current quantity.
I can't figure how to do that filtering. Any ideas?
Consider the graph data model below. The days are connected in a linked list but they contain timestamps. If I want to collect the
Stats
nodes between a range, I must first select on those day nodes and then I can select theStats
nodes that are in purple. From there I can specify that those purple nodes must be connected to theGroup
node in yellow that is connected to theLocation
that I specify.Now if I translate this pattern into Cypher, I get the following:
If you refactored your model to turn the
in_stock
relationship into a node with a timestamp, and model that node as a linked list, then you could select the most recent by specifying the pattern:This is the most performant way to do this. To manage pointers in a linked list that allow you to both query on a range (between timestamps) and to also query the N most recent items.