在neo4j中同时创建节点和关系 [英] Creating nodes and relationships at the same time in neo4j

查看:2169
本文介绍了在neo4j中同时创建节点和关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Neo4j中构建一个数据库,该数据库包含七个不同类型的节点,总共约4-5000个节点,并且它们之间约有40000个关系.我当前使用的密码是我首先使用以下代码创建节点:

I am trying to build an database in Neo4j with a structure that contains seven different types of nodes, in total around 4-5000 nodes and between them around 40000 relationships. The cypher code i am currently using is that i first create the nodes with the code:

Create (node1:type {name:'example1', type:'example2'})

该示例中约4000个具有唯一节点.

Around 4000 of that example with unique nodes.

然后我说出了这样的关系:

Then I've got relationships stated as such:

Create
(node1)-[:r]-(node51),
(node2)-[:r]-(node5),
(node3)-[:r]-(node2);

大约40000个这样的独特关系.

Around 40000 of such unique relationships.

对于较小比例的图形,这根本不是问题.但是有了这个,执行查询就永远不会停止加载.

With smaller scale graphs this has not been any problem at all. But with this one, the Executing query never stops loading.

关于如何使这种类型的查询起作用的任何建议?还是我应该怎么做?

Any suggestions on how I can make this type of query work? Or what i should do instead?

编辑.我要构建的是一个产品上的大图,它的发布,发布版本,功能等与构建Movie图示例一样.

edit. What I'm trying to build is a big graph over a product, with it's releases, release versions, features etc. in the same way as the Movie graph example is built.

该产品总共约有6个发行版,每个发行版都有约20个发行版.总共有371个功能,其中371个功能中也有438个功能版本.发行版本(总共120个),然后每个版本都有大约2-300个功能版本.这些Featureversions映射到其Feature,该Feature对数据库中的所有内容都具有依赖性.我还涉及硬件依赖性,例如可能在其上运行这些功能,在其上发布软件的硬件.因此,基本上我是使用诸如以下代码的密码来实现的:

The product has about 6 releases in total, each release has around 20 releaseversion. In total there is 371 features and of there 371 features there is also 438 featureversions. ever releaseversion (120 in total) then has around 2-300 featureversions each. These Featureversions are mapped to its Feature whom has dependencies towards a little bit of everything in the db. I have also involed HW dependencies such as the possible hw to run these Features on, releases on etc. so basicaly im using cypher code such as:

Create (Product1:Product {name:'ABC', type:'Product'})
Create (Release1:Release {name:'12A', type:'Release'})
Create (Release2:Release {name:'13A, type:'release'})
Create (ReleaseVersion1:ReleaseVersion {name:'12.0.1, type:'ReleaseVersion'})
Create (ReleaseVersion2:ReleaseVersion {name:'12.0.2, type:'ReleaseVersion'})    

下面是我使用

Create (Product1)<-[:Is_Version_Of]-(Release1),
(Product1)<-[:Is_Version_Of]-(Release2),
(Release2)<-[:Is_Version_Of]-(ReleaseVersion21),        

一直到功能,然后我还添加了它们之间的依赖关系,例如:

All the way down to features, and then I've also added dependencies between them such as:

(Feature1)-[:Requires]->(Feature239),
(Feature239)-[:Requires]->(Feature51);       

由于我不得不从许多不同的excel-sheets等中找到所有这些信息,因此我以这种方式编写代码,以为我可以将其放在一个大密码查询中,然后在本地主机上的/browser上运行它.只要我一次不使用超过4-5000个查询,它就可以很好地工作.然后,它最多在大约5-10秒内创建了整个数据库,但是现在,当我试图同时运行大约45000个查询时,它已经运行了将近24小时,并且仍在加载并说正在执行查询". ..".我想知道是否有什么可以改善我花费的时间的,最终是否会创建数据库?还是我可以做一些更聪明的索引或其他事情来提高性能?因为顺便说一下我现在编写的密码,因为数据库中的所有内容都与产品有某种联系,所以我无法将其分为几部分.我需要重写代码还是周围有任何平滑的方法?

Since i had to find all this information from many different excel-sheets etc, i made the code this way thinking i could just put it together in one mass cypher query and run it on the /browser on the localhost. it worked really good as long as i did not use more than 4-5000 queries at a time. Then it created the entire database in about 5-10 seconds at maximum, but now when I'm trying to run around 45000 queries at the same time it has been running for almost 24 hours, and are still loading and saying "executing query...". I wonder if there is anyway i can improve the time it takes, will the database eventually be created? or can i do some smarter indexes or other things to improve the performance? because by the way my cypher is written now i cannot divide it into pieces since everything in the database has some sort of connection to the product. Do i need to rewrite the code or is there any smooth way around?

推荐答案

您可以创建与单个create语句互连的多个节点和关系,如下所示:

You can create multiple nodes and relationships interlinked with a single create statement, like this:

create (a { name: "foo" })-[:HELLO]->(b {name : "bar"}),
       (c {name: "Baz"})-[:GOODBYE]->(d {name:"Quux"});

这是一种方法,而不是使用单个语句单独创建每个节点,然后使用单个语句创建每个关系.

So that's one approach, rather than creating each node individually with a single statement, then each relationship with a single statement.

您还可以通过先匹配然后创建以下内容来从对象创建多个关系:

You can also create multiple relationships from objects by matching first, then creating:

match (a {name: "foo"}), (d {name:"Quux"}) create (a)-[:BLAH]->(d);

当然,您可以有多个match子句和多个create子句.

Of course you could have multiple match clauses, and multiple create clauses there.

您可能尝试匹配给定类型的节点,然后从该类型的节点创建所有必要的关系.您有足够的关系,这将需要很多查询.确保已索引用于匹配节点的属性.随着您的数据库变大,对快速查找您要从中创建新关系的事物而言,这将非常重要.

You might try to match a given type of node, and then create all necessary relationships from that type of node. You have enough relationships that this is going to take many queries. Make sure you've indexed the property you're using to match the nodes. As your DB gets big, that's going to be important to permit fast lookup of things you're trying to create new relationships off of.

您尚未指定正在运行的查询不是停止加载".使用具体信息更新您的问题,并告诉我们您的尝试,也许可以为您提供帮助.

You haven't specified which query you're running that isn't "stopping loading". Update your question with specifics, and let us know what you've tried, and maybe it's possible to help.

这篇关于在neo4j中同时创建节点和关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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