Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-17-2020 06:37 AM
Hello Team,
I am writing a cypher query to find out how many people one person met with another. A person has a bidirectional relationship HAS_MET which indicates the number of counts they met each other as well as a timestamp.
query looks like this
//ahmad contact of contact in last 14 days
match (p:Person)-[rel1:HAS_MET]->()-[rel2:HAS_MET]->(other)
with p,other,rel1.timeStamp as firstContactTime, rel2.timeStamp as secondContactTime
where p.id=1 and datetime() > firstContactTime >datetime("2020-04-03T19:32:24") and datetime() > secondContactTime >datetime("2020-04-03T19:32:24")
return p, other
The above query will provide a response of Ahmad's contact and contact of a contact.
Now I am modifying the query to look like this
MATCH (p:Person)-[:HAS_MET*2]->(other)
WHERE p.id=1 and NOT (p)-[:HAS_MET]->(other)
return other, p
In this query how do I access timestamp property of HAS_MET relationship?
Solved! Go to Solution.
04-17-2020 10:39 AM
it is accessible in several ways. I suspect you may be most interested in just the last relationship in each path, not all the relationships? if that is the case you can explicitly access the last relationship in each path like this
MATCH t=(p:Person)-[:HAS_MET*2]->(other)
with last(relationships(t)) as r
return r.timeStamp
04-17-2020 10:39 AM
it is accessible in several ways. I suspect you may be most interested in just the last relationship in each path, not all the relationships? if that is the case you can explicitly access the last relationship in each path like this
MATCH t=(p:Person)-[:HAS_MET*2]->(other)
with last(relationships(t)) as r
return r.timeStamp
04-17-2020 11:48 AM
Thanks Joel, it works,
finally query look like this, as per your suggestion
MATCH a= (p:Person)-[:HAS_MET*2]->(other)
with *, last(relationships (a)) as rel
WHERE p.id=1 and NOT (p)-[:HAS_MET]->(other) and datetime() >rel.timeStamp>datetime("2020-04-03T19:32:24")
return other, p, rel
All the sessions of the conference are now available online