从 apoc.cypher.run 返回的地图中检索节点

Retrieve the nodes from a map returned by apoc.cypher.run

我正在使用 neo4j 3.5,我需要进行子查询,并且我正在使用“apoc.cypher.run”。

CALL apoc.cypher.run("MATCH (a:OBJECT)-[HAS_RELATIONSHIP]->(b:THING)
WHERE toLower(b.name) CONTAINS 'something'
RETURN a    
UNION
MATCH (a:Object)-[HAS_RELATIONSHIP]->(b:THING)--(c: Category)
WHERE toLower(c.name) CONTAINS 'something'
RETURN a", {})
yield value as a
WITH a
MATCH (a:Object)-[HAS_RELATIONSHIP]->(b:Thing)
OPTIONAL MATCH (b)--(c: Category) 
return a, b, c 

断线了:

MATCH (a:Object)-[HAS_RELATIONSHIP]->(b:Thing)

出现错误“a defined with conflicting type Map (expected Node)”,此查询有什么问题?

CALL apoc.cypher.run ()... yield value as a returns 一张地图,在你的情况下是一张地图(节点)的地图,这是预期的。
返回的地图结构为 {a:{node Properties}}.
这必须进一步分解以获得映射到内部的节点。

yield value as a
WITH a.a as a

从每个映射中检索节点:

CALL apoc.cypher.run("MATCH (a:OBJECT)-[HAS_RELATIONSHIP]->(b:THING)
WHERE toLower(b.name) CONTAINS 'something'
RETURN a    
UNION
MATCH (a:Object)-[HAS_RELATIONSHIP]->(b:THING)--(c: Category)
WHERE toLower(c.name) CONTAINS 'something'
RETURN a", {})
yield value as a
WITH a.a as a
MATCH (a:Object)-[HAS_RELATIONSHIP]->(b:Thing)
OPTIONAL MATCH (b)--(c: Category) 
return a, b, c