Neo4J / Cypher:如何过滤关系中最新日期的路径?

Neo4J / Cypher: How to filter for the path with the latest date in the relationship?

我是 Cypher 查询的新手。

(p:Person)-[e:Evaluated {rating:3, characteristic: "quality of kitchen", date: 14-09-2009})->(h:House {adress: xyz})

每栋房子都有多重特征。 每个房子都被多次评级(在不同的日期)。

我想实现的是匹配路径(p)-[e]-(h),但我只想过滤具有最近评估日期的路径。

此路径是进一步分析的起点。

这个过滤器应该可以与 WITH 或 WHERE 函数一起使用,但是在查询了很多之后我在这里试试运气:)

为简单起见,我假设您首先将 date 属性 更改为易于排序(例如,您使用 date 值,或者你使用格式 '2009-09-14').

您可以使用 ORDER BYLIMIT 来获取单个最新结果:

MATCH (p:Person)-[e:Evaluated {rating:3, characteristic: "quality of kitchen"}]->(h:House {address: '123 Main St'})
RETURN p, e, h
ORDER BY e.date DESC
LIMIT 1