# Shortest path between nodes have relationship properties as list of timestamps

**URL:** <https://community.neo4j.com/t/shortest-path-between-nodes-have-relationship-properties-as-list-of-timestamps/12274>\
**Category:** Cypher\
**Tags:** performance, browser, cypher\
**Created:** [November 26, 2019, 10:57pm UTC](https://community.neo4j.com/t/shortest-path-between-nodes-have-relationship-properties-as-list-of-timestamps/12274 "2019-11-26T22:57:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yashwanthv21](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/yashwanthv21/32/7622_2.png) [@Yashwanthv21](https://community.neo4j.com/u/Yashwanthv21)\
**Post date:** [November 26, 2019, 10:57pm UTC](https://community.neo4j.com/t/shortest-path-between-nodes-have-relationship-properties-as-list-of-timestamps/12274/1 "2019-11-26T22:57:50Z")

</div>

neo4j desktop 1.2.3 , trying the following query in the browser

The graph represents the call history between two persons and the relationship CALLED has property **timestamp**. **_This property is a list of timestamps_.**

The below code gives the shortest path, irrespective of the timestamp

```auto
MATCH (ms:Person { name: 'Martin Sheen' }),(cs:Person { name: 'Charlie Sheen' }), p = shortestPath((ms)-[:CALLED*]-(cs))
WITH p
WHERE length(p)> 1
RETURN p

```

I want to know the shortest path after time **t1** or between time **t1** and **t2**. I am not able to filter list properties using the Cypher query. But the below query doesn't work.

```auto
MATCH (ms:Person { name: 'Martin Sheen' }),(cs:Person { name: 'Charlie Sheen' }), p = shortestPath((ms)-[r:CALLED*]-(cs))
WITH p, r as relationships(p)
WHERE length(p)> 1 and all(r IN relationships(p) WHERE (time in r WHERE time > datetime({year:2019,month:3,day:31})))
RETURN p

```

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![shan](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/shan/32/7767_2.png) [@shan](https://community.neo4j.com/u/shan)\
**Post date:** [November 26, 2019, 11:07pm UTC](https://community.neo4j.com/t/shortest-path-between-nodes-have-relationship-properties-as-list-of-timestamps/12274/2 "2019-11-26T23:07:12Z")

</div>

You can possibly use cypher projection in algo.shortestPath. Here's a sample:

```auto
MATCH (ms:Person { name: 'Martin Sheen' }), (cs:Person { name: 'Charlie Sheen' })
CALL algo.shortestPath(ms, cs, null,{
nodeQuery:'MATCH (p:Person) RETURN id(n) as id',
relationshipQuery:'MATCH (p1:Person)-[r:CALLED]->(p2:Person) where r.time > datetime({year:2019,month:3,day:31}) RETURN id(p1) as source, id(p2) as target',
graph:'cypher'})
YIELD writeMillis,loadMillis,nodeCount, totalCost
RETURN writeMillis,loadMillis,nodeCount,totalCost

```

---

<div class="post-metadata">

**Author:** ![Yashwanthv21](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/yashwanthv21/32/7622_2.png) [@Yashwanthv21](https://community.neo4j.com/u/Yashwanthv21)\
**Post date:** [November 26, 2019, 11:57pm UTC](https://community.neo4j.com/t/shortest-path-between-nodes-have-relationship-properties-as-list-of-timestamps/12274/3 "2019-11-26T23:57:11Z")

</div>

Hi Shan,

> [@shan](#):
>
> relationshipQuery:'MATCH (p1:Person)-[r:CALLED]-\>(p2:Person) where r.time \> datetime({year:2019,month:3,day:31}) RETURN id(p1) as source, id(p2) as target',

The relationship **CALLED** has properties as list I am unable to loop through using two **WHERE** and check each timestamp.

```auto
...
relationshipQuery:'MATCH (p1:Node)-[re:IS_NEIGHBOR]->(p2:Node) where r IN re.timestamp WHERE time in r WHERE time > datetime({year:2019,month:3,day:31}) RETURN id(p1) as source, id(p2) as target',
...

```

Not sure if I am doing the right thing here.  
Thanks @shan

---

<div class="post-metadata">

**Author:** ![shan](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/shan/32/7767_2.png) [@shan](https://community.neo4j.com/u/shan)\
**Post date:** [November 27, 2019, 4:31am UTC](https://community.neo4j.com/t/shortest-path-between-nodes-have-relationship-properties-as-list-of-timestamps/12274/4 "2019-11-27T04:31:54Z")

</div>

How about this then:

```auto
MATCH (ms:Person { name: 'Martin Sheen' }), (cs:Person { name: 'Charlie Sheen' })
CALL algo.shortestPath(ms, cs, null,{
nodeQuery:'MATCH (p:Person) RETURN id(n) as id',
relationshipQuery:'MATCH (p1:Person)-[r:CALLED]->(p2:Person) where any(x in r.time where x > datetime({year:2019,month:3,day:31})) RETURN id(p1) as source, id(p2) as target',
graph:'cypher'})
YIELD writeMillis,loadMillis,nodeCount, totalCost
RETURN writeMillis,loadMillis,nodeCount,totalCost

```

---

<div class="post-metadata">

**Author:** ![Yashwanthv21](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/yashwanthv21/32/7622_2.png) [@Yashwanthv21](https://community.neo4j.com/u/Yashwanthv21)\
**Post date:** [November 27, 2019, 6:07am UTC](https://community.neo4j.com/t/shortest-path-between-nodes-have-relationship-properties-as-list-of-timestamps/12274/5 "2019-11-27T06:07:35Z")

</div>

Thank you Shan. It works but for other who might have similar question _while comparing timestamps make sure both the timestamps are in same format_

One more step before the final solutions.  
How can get the graph to show or json results, I am able to get the Node ids using **stream**  
I looked at the docs and tried to find in forum, but I could not find any.
