【问题标题】:Neo4j error when importing json file via Cypher通过 Cypher 导入 json 文件时出现 Neo4j 错误
【发布时间】:2019-12-28 01:34:13
【问题描述】:

我正在尝试将 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"}}

【问题讨论】:

  • 错误表明,您的 JSON 中的值不属于受支持的类型。你能分享示例 JSON 吗?
  • 我在@Raj上面添加了json文件的内容

标签: neo4j cypher neo4j-apoc bloodhound


【解决方案1】:

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 文件生成的图形结构是什么,然后您可能需要 UNWIND value.domains 数组而不是 CREATE (n: Group) n += value 并创建节点通过遍历表示 JSON 的嵌套映射和属性。

例如,以下将创建具有“名称”属性的 Group 节点,并使用来自 Trusts 数组的信息创建 Trust 节点:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多