我想根据指标 Node
在一组 Node (报告 Node
)中创建一个新 Node (事件 Node
)(每个报告 Node 都有几个与之相关的指标 Node )。我想使用规则设置新的事件 Node
:
- 一个
报告 Node
仅连接一个事件 Node
- 如果多个
指标 Node
具有相同的属性“pattern”,则它们属于同一事件 Node
这是我的查询代码:
OPTIONAL MATCH
(indicator_1_1:indicator)<-[:REFERS_TO]-(report_1:report)-[:REFERS_TO]->(indicator_1_2:indicator),
(indicator_2_1:indicator)<-[:REFERS_TO]-(report_2:report)-[:REFERS_TO]->(indicator_2_2:indicator)
WHERE
indicator_1_1.pattern=indicator_2_1.pattern
and
indicator_1_2.pattern=indicator_2_2.pattern
MERGE
(report_1)-[:related_to]->(event:EVENT)<-[:related_to]-(report_2)
但我希望三个报告 Node 属于一个事件 Node 。 我想知道应该对查询进行哪些更改,或者在获取两个事件 Node 后下一步应该采取什么步骤。
另外,我想知道是否有比我的更高效的查询代码。
谢谢!
最佳答案
我没有任何数据可以确认,但我认为对您的 Cypher 查询进行一点小小的更改就会产生您想要的结果。
来自 Neo4j Cypher 手册 MERGE
的章节(我的重点是添加的)。
When using
MERGE
on full patterns, the behavior is that either the whole pattern matches, or the whole pattern is created.MERGE
will not partially use existing patterns — it’s all or nothing. If partial matches are needed, this can be accomplished by splitting a pattern up into multipleMERGE
clauses.
所以,接下来,我想如果你改变
MERGE (report_1)-[:related_to]->(event:EVENT)<-[:related_to]-(report_2)
至
MERGE (report_1)-[:related_to]->(event:EVENT)
MERGE (event)<-[:related_to]-(report_2)
...您将阻止创建额外的 :EVENT
Node 并获得您正在寻找的图表。
关于node.js - Neo4j : How to create a unique node instead of set of nodes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55312672/