Neo4j 加载 CSV 以创建动态关系类型 [英] Neo4j load CSV to create dynamic relationship types

查看:30
本文介绍了Neo4j 加载 CSV 以创建动态关系类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以将特定标签的 CSV 加载到 Neo4j 中(比如 PERSON),并且在标签 PERSON 下创建节点.

I can load CSV into Neo4j for a specific label (say PERSON) and the nodes are created under the label PERSON.

我还有另一个 CSV 来说明这个人之间的关系,它看起来像:

I also have another CSV to illustrate the relationships between the person and it looks like:

name1, relation, name2
a, LOVE, b
a, HATE, c

我想在这些对之间创建关系,因此创建的关系应该是LOVE"、HATE"等,而不是像下面的脚本那样严格的RELATION:>

I want to create a relationship between these pairs and the relationship thus created should be "LOVE", "HATE", etc, instead of a rigid RELATION as done by the below script:

load csv with headers from "file:///d:/Resources/Neo4j/person-rel.csv" as p
match (a:PERSON) where a.name=p.name1
match (b:PERSON) where b.name=p.name2
merge (a)-[r:REL {relation: p.REL}]->(b)

通过这样做,我有一堆REL-类型的关系,但没有LOVE-和HATE-关系.

By doing this, I have a bunch of REL-type relations but not LOVE- and HATE-relations.

换句话说,我希望脚本最后一行中的 REL 被动态分配.然后我可以使用 Neo4j API 查询所有关系类型.

In another word, I want the REL in the last line of the script to be dynamically assigned. And then I can query out all the relationship types using Neo4j API.

这可能吗?

推荐答案

您可以安装 APOC库然后使用apoc.merge.relationship

apoc.merge.relationship(startNode, relType, {key:value, ...}, {key:value, ...}, endNode) - 与动态类型的合并关系

apoc.merge.relationship(startNode, relType, {key:value, ...}, {key:value, ...}, endNode) - merge relationship with dynamic type

load csv with headers from "file:///d:/Resources/Neo4j/person-rel.csv" as p
match (a:PERSON) where a.name=p.name1
match (b:PERSON) where b.name=p.name2
call apoc.merge.relationship(a,p.REL,{},{},b) yield rel
return count(*);

这篇关于Neo4j 加载 CSV 以创建动态关系类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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