gpt4 book ai didi

python - Py2neo Neo4j批量提交报错

转载 作者:太空宇宙 更新时间:2023-11-04 10:34:00 24 4
gpt4 key购买 nike

我有一个包含大约 140 万个节点数据的 json 文件,我想为此构建一个 Neo4j 图形数据库。我尝试使用py2neo的批量提交功能。我的代码如下:

# the variable words is a list containing node names
from py2neo import neo4j
batch = neo4j.WriteBatch(graph_db)
nodedict = {}
# I decided to use a dictionary because I would be creating relationships
# by referring to the dictionary entries later
for i in words:
nodedict[i] = batch.create({"name":i})
results = batch.submit()

显示错误如下:

Traceback (most recent call last):
File "test.py", line 36, in <module>
results = batch.submit()
File "/usr/lib/python2.6/site-packages/py2neo/neo4j.py", line 2116, in submit
for response in self._submit()
File "/usr/lib/python2.6/site-packages/py2neo/neo4j.py", line 2085, in _submit
for id_, request in enumerate(self.requests)
File "/usr/lib/python2.6/site-packages/py2neo/rest.py", line 427, in _send
return self._client().send(request)
File "/usr/lib/python2.6/site-packages/py2neo/rest.py", line 364, in send
return Response(request.graph_db, rs.status, request.uri, rs.getheader("Loc$
File "/usr/lib/python2.6/site-packages/py2neo/rest.py", line 278, in __init__
raise SystemError(body)
SystemError: None

谁能告诉我这里到底发生了什么?它与批量查询非常大的事实有什么关系吗?如果是这样,可以做什么?提前致谢! :)

最佳答案

这就是我想出的(感谢这个问题:py2neo - Neo4j - System Error - Create Batch Nodes/Relationships):

py2neo 批量提交功能在可以进行的查询方面有其自身的限制。虽然我无法获得上限的确切数量,但我尝试将每批查询的数量限制为 5000。因此我决定运行以下代码:

# the variable words is a list containing node names
from py2neo import neo4j
batch = neo4j.WriteBatch(graph_db)
nodedict = {}
# I decided to use a dictionary because I would be creating relationships
# by referring to the dictionary entries later

for index, i in enumerate(words):
nodedict[i] = batch.create({"name":i})
if index%5000 == 0:
batch.submit()
batch = neo4j.WriteBatch(graph_db) # As stated by Nigel below, I'm creating a new batch
batch.submit() #for the final batch

通过这种方式,我发送了批量请求(大小为 5k 的查询)并成功创建了我的整个图表!

关于python - Py2neo Neo4j批量提交报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24657190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com