通过 Cypher 导入 json 文件时出现 Neo4j 错误

Neo4j error when importing json file via Cypher

我正在尝试将 Bloodhound/SharpHound json 文件导入 Neo4j,但我 运行 出现以下错误:

{ "Neo4j only supports a subset of Cypher types for storage as singleton or array properties. Please refer to section cypher/syntax/values of the manual for more details.": 1 }

这是我的脚本:

call apoc.periodic.iterate('
call apoc.load.json("file:///sessions/20190822113758_groups.json") yield value
','
create (n:Groups) SET n += value
',{batchSize:10000})

这是 json 文件中的内容:

{"domains":[{"Properties":{"objectsid":"S-1-2-2515432156546548","highvalue":true,"domain":"somethingone.COM"},"Name":"somethingone.COM","Links":null,"Trusts":[{"TargetName":"some.somethingtwo.COM","IsTransitive":true,"TrustDirection":2,"TrustType":"External"},{"TargetName":"something-three.COM","IsTransitive":true,"TrustDirection":2,"TrustType":"ParentChild"},{"TargetName":"somethingfour.COM","IsTransitive":true,"TrustDirection":0,"TrustType":"External"}],"Aces":null,"ChildOus":null,"Computers":null,"Users":null}],"meta":{"count":1,"type":"domains"}}

Neo 不支持作为地图或地图数组的节点的属性。例如,以下都不起作用:

CREATE (n: Group) SET n.prop = { key: "value" }

Neo.ClientError.Statement.TypeError: Property values can only be of primitive types or arrays thereof
CREATE (n: Group) SET n.prop = [{ key: "value" }, { key: "value" }]

Neo.ClientError.Statement.TypeError: Neo4j only supports a subset of Cypher types for storage as singleton or array properties. Please refer to section cypher/syntax/values of the manual for more details.

第二个是您看到的错误,但它们基本上是等价的 - 您正在尝试将 属性 添加到具有不受支持的数据类型的节点。如果您查看 JSON 文件,domains 地图本身就是一个地图数组,它们本身包含更多地图...

您需要考虑要从 JSON 文件生成的图形结构是什么,然后您可能需要 [=15= 而不是 CREATE (n: Group) n += value ] value.domains 数组并通过遍历表示 JSON.

的嵌套映射来创建节点和属性

例如,以下将使用 'Name' 属性 创建组节点,并使用 Trusts 数组中的信息创建信任节点:

call apoc.load.json("file:///sessions/20190822113758_groups.json") yield value
UNWIND value.domains as domain
MERGE (g: Group { Name: domain.Name })
WITH g, domain.Trusts as trusts
UNWIND trusts as trust
MERGE (t: Trust { TrustType: trust.TrustType, TrustDirection: trust.TrustDirection, TargetName: trust.TargetName, IsTransitive: trust.IsTransitive })
MERGE (t)-[:BELONGS_TO]->(g)
RETURN t, g

您可能会发现您需要多次调用 apoc.load.json 并分段创建图表 - 也许首先创建组,然后是信任,然后是属性等等,在您进行时加入节点,这很难告诉示例 JSON 文件中的所有 nulls