如何避免Memgraph Lab执行大量Cypher时出现请求实体过大错误?
解决Memgraph Lab执行大体积Cypher语句时的"request entity too large"错误
问题描述
我有一组约700行的Cypher CREATE语句,示例代码如下:
CREATE (:System {name: "Game.Zones.CellCheckSystem", componentTypes: ["Game.Zones.Block", "Game.Common.Owner", "Game.Objects.Transform", "Game.Net.EdgeGeometry", "Game.Net.StartNodeGeometry", "Game.Net.EndNodeGeometry", "Game.Net.Composition", "Game.Prefabs.PrefabRef", "Game.Prefabs.NetCompositionData", "Game.Prefabs.RoadComposition", "Game.Prefabs.AreaGeometryData", "Game.Prefabs.ObjectGeometryData", "Game.Common.Native", "Game.Zones.ValidArea", "Game.Zones.ValidArea", "Game.Net.BuildOrder", "Game.Prefabs.SpawnableBuildingData", "Game.Prefabs.SignatureBuildingData", "Game.Prefabs.PlaceholderBuildingData", "Game.Prefabs.ZoneData", "Game.Common.Updated"]}) CREATE (:System {name: "Game.Zones.LoadSystem", componentTypes: []}) CREATE (:System {name: "Game.Zones.SearchSystem", componentTypes: ["Game.Zones.Block", "Game.Common.Created", "Game.Common.Deleted"]}) CREATE (:System {name: "Game.Zones.UpdateCollectSystem", componentTypes: ["Game.Zones.Block", "Game.Common.Created", "Game.Common.Deleted"]})
将所有语句一次性复制到Memgraph Lab执行时,触发错误:
Uh oh! Something unexpected went wrong. Please try again or contact Memgraph support. Details: request entity too large
分批复制100行执行则全部成功,说明单个CREATE语句本身没有问题。我使用Docker部署的Memgraph 2.13平台版,希望找到无需拆分语句的解决办法。
解决办法
1. 用Memgraph CLI执行语句
通过Docker容器内的Memgraph CLI直接读取文件执行,避开Memgraph Lab的请求大小限制:
- 把所有Cypher语句保存到本地文件,比如命名为
systems.cypher - 将文件复制到Memgraph容器内:
docker cp systems.cypher <你的Memgraph容器名称>:/tmp/ - 进入Memgraph的命令行工具:
docker exec -it <你的Memgraph容器名称> mgconsole - 在CLI中执行文件内容:
\i /tmp/systems.cypher
2. 调整Memgraph Lab的请求大小限制
如果必须使用Memgraph Lab界面,可通过修改配置提升最大请求体积:
- 打开你的Docker部署配置(比如
docker-compose.yml),找到Memgraph Lab的服务配置 - 添加环境变量设置最大请求大小,比如设置为10MB:
services: memgraph-lab: # 其他配置项... environment: - MAX_REQUEST_SIZE=10MB - 重启Memgraph Lab容器使配置生效
3. 合并多个CREATE语句
把分散的单行CREATE合并成一个语句,减少请求的结构体积:
将所有CREATE用逗号分隔,放在同一个语句块里,比如:
CREATE (:System {name: "Game.Zones.CellCheckSystem", componentTypes: ["Game.Zones.Block", ...]}), (:System {name: "Game.Zones.LoadSystem", componentTypes: []}), (:System {name: "Game.Zones.SearchSystem", componentTypes: ["Game.Zones.Block", ...]}), (:System {name: "Game.Zones.UpdateCollectSystem", componentTypes: ["Game.Zones.Block", ...]});
这样700行的语句可以合并成1个大的CREATE语句,大幅降低请求的整体体积,避免触发大小限制。
内容的提问来源于stack exchange,提问作者CharlesTheMan
相关产品推荐
相关产品推荐

