删除neo4j中的MIN计数数据

时间:2018-05-24 06:28:09

标签: neo4j count min collect

我想在对neo4j进行一些计数后删除一些数据。这种方法可以手动完成(计算数据然后删除数据),但我需要有人指出我是否可能自动执行此操作(计算数据并删除同一查询中的数据)。在使用neo4j中的min()函数进行一些计数后,我找不到返回最小/最小数据的方法。我可以使用order by和限制数据来解决方法,但是如果我想要这样做,我需要确保没有其他选项。

这是指向data的链接。数据是自定义事件日志,仅包含case_id和活动名称。

所以这就是我已经尝试过的:

//LOAD DATA
LOAD CSV with headers FROM "file:///*.csv"
  AS line
Create (:Activity {CaseId:line.Case_ID,
Name:line.Activity })
LOAD CSV with headers FROM "file:///*.csv"
  AS line
Create (:CaseActivity {CaseId:line.Case_ID,
Name:line.Activity })

//SEQUENCE DISCOVERY
match (c:Activity)
with collect(c) AS Caselist
unwind range(0,Size(Caselist) - 2) as idx
with Caselist[idx] AS s1, Caselist[idx+1] AS s2
match (b:CaseActivity),(a:CaseActivity)
where s1.CaseId = s2.CaseId AND
s1.Name = a.Name AND
s2.Name = b.Name AND
s1.CaseId = a.CaseId AND
s2.CaseId = b.CaseId
merge (a)-[:NEXT {relation:"NEXT"}]->(b)

match(a:Activity) 
with a.CaseId as id, 
collect (a.Name) as Trace_Type 
match(b:CaseActivity) 
where id = b.CaseId 
return count (distinct b.CaseId) as Frequencies, Trace_Type, Collect(distinct b.CaseId) as CaseId 
order by Frequencies desc

1 个答案:

答案 0 :(得分:0)

您的问题未指定要删除的内容。此查询假定您希望上次查询删除b个节点(并返回有关已删除的b节点的一些数据):

MATCH (a:Activity) 
WITH a.CaseId as id, COLLECT(a.Name) AS Trace_Type 
MATCH (b:CaseActivity) 
WHERE id = b.CaseId 
WITH
  COUNT(distinct b.CaseId) AS Frequencies,
  Trace_Type,
  COLLECT(distinct b.CaseId) AS CaseId,
  COLLECT(DISTINCT b) AS bs
FOREACH(x IN bs | DELETE x)
RETURN Frequencies, Trace_Type, CaseId
ORDER BY Frequencies DESC;

包含从已删除的b节点(如FrequenciesCaseId)获取的值的变量在删除节点后仍然有效。

有关您的具体示例的一个棘手的事情是,您的上一个WITH子句使用aggregationTrace_Type作为分组键。为了让我的答案避免更改分组键(从而可能更改返回的结果),我只是将COLLECT(DISTINCT b) AS bs添加到WITH子句中。然后,由于每个bsb个节点的列表(对于Trace_Type),我使用FOREACH删除每个列表中的节点。