Neo4J relationships with time constraints
Asked Answered
K

1

12

I have relationships between nodes which are only valid for a specific time. Simple example: Person P lived at Address A from time t1 to time t2. I can put a validFrom and a validUntil property on the relationship, but when using cypher, I have to filer this in the WHERE clause, but I would want it in the MATCH clause.

The reason why I want this in the MATCH clause is that it may potentially traverse a large subgraph, only to find out later that most of it could be ignored. This is especially so with a large set of historic relationships.

I can make seperate validFrom and validUntil relationships to specific date nodes. That way I can use MATCH. This would be OK if I have a limited set of such time nodes, but when I have to store timestamps it is not practical to do this.

How can you optimize Cypher for this type of querying? How to time-slice a graph with nodes and relationships having time-validity indicators?

Kloman answered 12/3, 2013 at 15:31 Comment(3)
Cypher automatically pulls expressions into match clauses whenever possible, so they are evaluated as soon as they can be.Ats
Can you actually show your query?Ats
Did you come up with a solution that worked for this please?Margaretemargaretha
T
5

Have you seen the timeline modeling described here: http://docs.neo4j.org/chunked/milestone/cypher-cookbook-path-tree.html

Teodoor answered 12/3, 2013 at 15:48 Comment(2)
That works for limited event timings, but you can't model time down to seconds or smaller. It is what I suggested already, but doesn't scale out.Kloman
What about a split model where you take care of days using the above model and keeping only time on the node? Not sure about the kind of data you have but you could also extend the same model to time and just create the time relations on demand...again, this may be impractical for the data pattern you haveTeodoor

© 2022 - 2024 — McMap. All rights reserved.