简体   繁体   English

如何找到Neo4j和Cypher中的一系列连接节点的头部?

[英]How to find the head of a series of connected nodes in Neo4j with Cypher?

I'm still quite new with Neo4j and I thought this would be a really easy task but after some serious goolging I realized it's probably not so easy (or I just used the wrong keywords...)我对 Neo4j 还是很陌生,我认为这将是一项非常容易的任务,但经过一番认真的搜索后,我意识到这可能并不那么容易(或者我只是使用了错误的关键字......)

I'm trying to find the head of a series of nodes connected with a particular relationship.我试图找到与特定关系相关的一系列节点的头部。 The relationship is based on the timestamp property of each node.该关系基于每个节点的时间戳属性。 Here's my first attempt query:这是我的第一次尝试查询:

MATCH (n1)-[:RELATIONSHIP*]->()
ORDER BY n1.timestamp
RETURN n1

Then I found the startNode function and tried:然后我找到了startNode function 并尝试了:

MATCH ()-[rel:RELATIONSHIP]->()
RETURN startNode(rel)

But it doesn't always return the start nodes.但它并不总是返回起始节点。 Sometimes it returns some nodes in the middle.有时它会在中间返回一些节点。 I'd like to find all of the heads and connect them to nodes of some other labels.我想找到所有的头并将它们连接到其他标签的节点。 Thanks!谢谢!

Turned out the answer is extremely easy...thanks to @tomasi from the Neo4j Slack Group.原来答案非常简单……感谢 Neo4j Slack Group 的@tomasi。

Here in case anyone needs it:在这里以防万一有人需要它:

MATCH (n:Label)
WHERE NOT ()-[:RELATIONSHIP]->(n)
RETURN n

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM