Neo4j加载CSV创建动态关系类型 [英] Neo4j load CSV to create dynamic relationship types
问题描述
我可以为特定标签(例如PERSON
)将CSV加载到Neo4j中,并在标签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
You can install the APOC library and then use 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屋!