我正在将节点和关系插入到我的neo4j DB中(graphenedb但也发生在本地)。 大约500次插入后,插入语句卡住。 重新启动neo4j服务器后,相同的插入件将照常工作,我可以继续进行下一个〜500个插入件。
您有任何线索为什么会卡住吗?
一个插入语句如下:
MERGE (b0:Company{company_id:{b1},universal_name:{b2},company_name:{b3}})
ON CREATE SET b0.funding_total_usd = null
ON MATCH SET b0.funding_total_usd = null
MERGE (b13:Industry{name:{b12}})
MERGE (b0)-[:company_industry]->(b13)
MERGE (b15:Category{name:{b14}})
MERGE (b0)-[:company_category]->(b15)
MERGE (b17:Category{name:{b16}})
MERGE (b0)-[:company_category]->(b17)
MERGE (b19:Category{name:{b18}})
MERGE (b0)-[:company_category]->(b19)
MERGE (b21:Category{name:{b20}})
MERGE (b0)-[:company_category]->(b21)
MERGE (b23:Category{name:{b22}})
MERGE (b0)-[:company_category]->(b23)
MERGE (b25:Category{name:{b24}})
MERGE (b0)-[:company_category]->(b25)
MERGE (b27:Category{name:{b26}})
MERGE (b0)-[:company_category]->(b27)
存在索引:
Indexes
ON :Category(name) ONLINE (for uniqueness constraint)
ON :Company(company_id) ONLINE (for uniqueness constraint)
ON :Company(universal_name) ONLINE (for uniqueness constraint)
ON :Industry(name) ONLINE (for uniqueness constraint)
Constraints
ON ( category:Category ) ASSERT category.name IS UNIQUE
ON ( company:Company ) ASSERT company.company_id IS UNIQUE
ON ( company:Company ) ASSERT company.universal_name IS UNIQUE
ON ( industry:Industry ) ASSERT industry.name IS UNIQUE
我使用以下PHP代码提交该语句:
$config = \GraphAware\Bolt\Configuration::create()
->withCredentials($user, $pw)
->withTimeout($timeout);
if($ssl) {
$config = $config->withTLSMode(\GraphAware\Bolt\Configuration::TLSMODE_REQUIRED);
}
$driver = \GraphAware\Bolt\GraphDatabase::driver($uri, $config);
$driver->session()->run($query, $binds);
经过测试的版本:3.4.12和3.5.1
@edit:添加了用于提交语句和neo4j版本的代码。
答案 0 :(得分:1)
您应该分批插入,而不应该为每个单独的节点显式创建单独的变量。相反,请查看是否可以提供参数,其中包括可以使用UNWIND一次处理的属性列表。
请参阅我们的batching tips and tricks中的一些内容。
应用于您的查询时,每批次的参数输入可能类似于以下内容:
{条目:[{companyId:12345,universalName:'foo',companyName:'bar', Industry:'industry',类别:[{name:'cat1'},{name:'cat2'}, {name:'cat3'}]}]}
每批执行的查询本身如下所示:
UNWIND $entries as entry
MERGE (c:Company{company_id:entry.companyId, universal_name:entry.universalName, company_name:entry.companyName})
SET c.funding_total_usd = null
MERGE (industry:Industry{name:entry.industry})
MERGE (c)-[:company_industry]->(industry)
WITH entry, c
UNWIND entry.categories as cat
MERGE (category:Category{name:cat.name})
MERGE (c)-[:company_category]->(category)