如何使用属性信息生成关系[Node4j] [英] How to generate relationships using property information [Node4j]
问题描述
我已经导入了一个CSV,其中每个节点包含3列. id,parent_id和标题.这是我在mysql中使用的简单树结构.现在,我需要考虑parent_id数据来创建这些节点之间的关系.因此,每个节点到节点将具有2个父级和子级关系.我对node4j真的很陌生,并提出建议吗?
I have imported a CSV where each Node contains 3 columns. id, parent_id, and title. This is a simple tree structure i had in mysql. Now i need to create the relationships between those nodes considering the parent_id data. So each node to node will have 2 relationships as parent and child. Im really new to node4j and suggestions ?
我尝试跟随,但没有运气
i tried following, but no luck
MATCH (b:Branch {id}), (bb:Branch {parent_id})
CREATE (b)-[:PARENT]->(bb)
推荐答案
似乎您的密码非常接近.您要做的第一件事是在标签Branch
的id
和parent_id
属性上创建一个索引.
It seems as though your cypher is very close. The first thing you are going to want to do is create an index on the id
and parent_id
properties for the label Branch
.
CREATE INDEX ON :Branch(id)
CREATE INDEX ON :Branch(parent_id)
一旦创建了索引,您想要将所有带有标签Branch
的节点进行匹配(我将使用一个特定的值来限制它,以开始确保您确实创建了想要的对象),并为每个节点找到对应的父节点通过匹配索引属性.
Once you have indexes created you want to match all of the nodes with the label Branch
(I would limit this with a specific value to start to make sure you create exactly what you want) and for each find the corresponding parent by matching on your indexed attributes.
MATCH (b:Branch), (bb:Branch)
WHERE b.id = ???
AND b.parent_id = bb.id
CREATE (b)-[:PARENT]->(bb)
一旦您已经在一个分支上证明了这一点,并且您得到了预期的结果,那么我希望我一次将它用于更多分支.您仍然可以选择分批执行此操作,具体取决于图形中的分支数量.
Once you have proved this out on one branch and you get the results you expect I would run it for more branches at once. You could still choose to do it in batches depending on the number of branches in your graph.
创建所有:PARENT
关系后,可以选择删除所有parent_id
属性.
After you have created all of the :PARENT
relationships you could optionally remove all of the parent_id
properties.
MATCH (b:Branch)-[:PARENT]->(:Branch)
WHERE exists(b.parent_id)
REMOVE b.parent_id
这篇关于如何使用属性信息生成关系[Node4j]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!