简体   繁体   English

在Neo4j中创建后续节点之间的关系(日期属性)

[英]Create Relationships between Consequent Nodes (on date attribute) in Neo4j

I am trying to get a csv into Neo4j. 我正在尝试将CS​​V导入Neo4j。 As it consists of log entries, I'd like to connect nodes with a NEXT-pointer/relationship when the corresponding logs have been created at subsequent times. 由于它由日志条目组成,因此我想在以后的时间创建相应的日志时使用NEXT指针/关系连接节点。

LOAD CSV WITH HEADERS FROM 'http://localhost/Export.csv' AS line
CREATE (:Entry { date: line[0], ...})

MATCH (n)
RETURN n
ORDER BY n:date


MATCH (a:Entry),(b:Entry),(c:Entry)
WITH p AS min(b:date) 
WHERE a:date < b:date AND c.date = p
CREATE (a)-[r:NEXT]->(c)

The last four lines do not work however. 最后四行不起作用。 What I try is to get the earliest entry 'c' out of the group of entries 'b' with a larger timestamp than 'a'. 我尝试的是从条目“ b”中获取最早的条目“ c”,其时间戳比“ a”大。 Can anyone help me out here? 有人可以帮我从这里出去吗?

Not sure if I understood your question correctly: you have a csv file containing log records with a timestamp. 不知道我是否正确理解了您的问题:您是否有一个csv文件,其中包含带有时间戳的日志记录。 Each line contains one record. 每行包含一个记录。 You want to interconnect the events to form a linked list based on a timestamp? 您想将事件互连以形成基于时间戳的链接列表吗?

In this case I'd split up the process into two steps: 在这种情况下,我将流程分为两个步骤:

  1. using LOAD CSV create a node with a data property for each line 使用LOAD CSV为每行创建一个具有data属性的节点
  2. afterwards connect the entries using eg a cypher statement like this: 然后使用如下密码语句连接条目:

.

MATCH (e:Entry) 
WITH e ORDER BY e.date DESC
WITH collect(e) as entries 
FOREACH(i in RANGE(0, length(entries)-2) | 
  FOREACH(e1 in [entries[i]] | 
    FOREACH(e2 in [entries[i+1]] |  
       MERGE (e1)-[:NEXT]->(e2))))

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

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