Filter Nodes and relations by relationship property

I have a simple database with person and building nodes. The relationships between these are visits with an arrival time and departure time. To start, I am attempting to build a query that shows all the arrivals that started between two datetimes.

Here is my query so far

MATCH path=(e)-[r:VISITED]->(b)
where all(rel in relationships(path) where rel.Visit_Arrive_Time > datetime({year:2020,month:5,day:30,hour:10}) and rel.Visit_Arrive_Time > datetime({year:2020,month:5,day:30,hour:13}))
return e,b

However the result appears to show more nodes and relationship than I expect:

When I run the following I get a similar result:

MATCH path=(e)-[r:VISITED {Visit_Depart_Time:datetime("2020-05-10T18:05:34Z")}]->(b) return e,b,r


Though I am asking for a specific timestamp, I get all the relationships between the two nodes. Sage does have a visit with that arrival time. However I want only the single relationship.

I am pretty new to Neo4j so please excuse my newness. I am fairly sure that my lack is a core concept I need to review in the docs. Any input is appreciated.

Ultimately I would like to show any visit that occurred to the window between that time to a location. Then be able to show subsequent visits from those times forward.

  • neo4j version: 4.0.2 Enterprise
  • desktop version: 1.2.7.1676

Hi @rileyjenk,

Welcome to Neo4j Community!!

You do not need to use All (). When you wrote all(rel in relationships(path).... You are instructing that relationship(path) is an list, although it is not .

If you have stored rel.Visit_Arrive_Time as DateTime then try below:

MATCH (e)-[r:VISITED]->(b)
where datetime("2020-06-10T18:05:34Z")> r.Visit_Arrive_Time>datetime("2020-04-10T18:05:34Z")
return e,b

Also visit below if this is the case

Ah I see what you mean by use of the ALL statement. Thanks!

Ha! I am not going crazy. Wasn't sure what to look for. This really helps!