Neo4j:将不同的节点链接到一个节点 [英] Neo4j: Link Different Nodes to the one node

查看:632
本文介绍了Neo4j:将不同的节点链接到一个节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您有以下4个节点:

Let's say you have the following 4 nodes:

设置1: (操作:事件日志",时间戳:3461000) (操作:正常运行时间报告",时间戳记:3461000)

Set 1: (act: "Event Log", timestamp: 3461000) (act: "Uptime Report", timestamp: 3461000)

设置2: (操作:事件日志",时间戳:149100) (操作:正常运行时间报告",时间戳记:149100)

Set 2: (act: "Event Log", timestamp: 149100) (act: "Uptime Report", timestamp: 149100)

我试图弄清楚如何将每组节点映射到一个节点.我尝试了以下Cypher,但所有4个节点都仅映射到一个节点,(a)而不是创建两个(a)节点并分别映射2个集合.是否有必要寻找与(act)节点匹配的时间戳的条件?然后,如果时间戳匹配,那么将这些节点链接到(a)?任何帮助将不胜感激.

I am trying to figure out how to map each set of nodes to one node. I tried the following Cypher but all 4 nodes are mapping to only one node, (a) instead of creating two (a) nodes and mapping the 2 sets respectively. Is it necessary to have a condition that looks for the matching timestamp of the (act) nodes? Then, if the timestamp do match then link those nodes to (a)? Any help would be greatly appreciated.

MATCH (seconds)<-[:AT_TIME]-(act)--(obj) 
WHERE reqObj.filename IN ["6013", "6005"]
MERGE (a:Abs{name: 'SigEvent'})
CREATE (reqAct)-[:LINK]->(a)

推荐答案

因此,如果我理解正确,则您希望为act节点中每个不同的时间戳创建一个:Abs节点.为此,我们需要按时间戳聚合行为节点(因此,每个不同的时间戳将只获得一行),然后创建:Abs节点,然后执行FOREACH来创建与新节点的关系. /p>

So if I understand correctly, you want an :Abs node for each distinct timestamp in the act nodes. To do this, we'll need to aggregate act nodes by timestamp (so you'll get only a single row per distinct timestamp), then CREATE the :Abs node, then do a FOREACH to create the relationships to the new node.

MATCH (act)--(obj) 
WHERE obj.filename IN ["6013", "6005"]
WITH act.timestamp as timestamp, collect(DISTINCT act) as acts
CREATE (a:Abs{name: 'SigEvent'}) // created per row, so per distinct timestamp
FOREACH (act in acts | CREATE (act)-[:LINK]->(a))

我将匹配模式的一部分移到了seconds上,因为它看起来并不像您正在使用的那样.

I removed the part of the match pattern to seconds as it didn't look like you were using that.

此查询中存在一个主要问题.由于您没有在匹配模式中使用标签,因此该匹配无法使用任何索引查找,因此此操作将对所有节点进行扫描,这将导致图形增长而导致糟糕的性能.您至少需要在其中一个标签上贴上标签.看来您打算在obj.filename上进行索引查找,因此在MATCH模式中将适当的标签添加到obj,以便可以使用索引(如果已创建).

There is a major problem in this query though. This match can't use any index lookup since you aren't using labels in the match pattern, so this is doing an all nodes scan which will result in terrible performance as the graph grows. You at least need a label on one of these. It looks like you intend to do an index lookup on obj.filename, so add the appropriate label to obj in your MATCH pattern so your index (if you've created one) can be used.

这篇关于Neo4j:将不同的节点链接到一个节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆