node.js - Neo4j : How to create a unique node instead of set of nodes

标签 node.js neo4j cypher

我想根据指标 Node 在一组 Node (报告 Node )中创建一个新 Node (事件 Node )(每个报告 Node 都有几个与之相关的指标 Node )。我想使用规则设置新的事件 Node :

  1. 一个报告 Node 仅连接一个事件 Node
  2. 如果多个指标 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)

得到如下结果, enter image description here

但我希望三个报告 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 multiple MERGE 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/

相关文章:

node.js - 通过 npm 升级 Node.js 时出错

node.js - 删除模块目录后 npm install 不再可能

node.js - MongoDB 与 Node.js,脚本正在等待...等什么?

java - 一起使用 Neo4j Core Java API 和终端控制台

php - 使用 neo4jphp 获取用户帖子,包括喜欢和评论

neo4j - 如何使用 Cypher 在 Neo4j 中复制子图

neo4j 编辑距离搜索

neo4j - 从 Dropbox 加载 Neo4j 的 CSV 文件

node.js - 如何使用 DynamoDB 批量删除?

garbage-collection - Neo4j 内存不足/GC 错误