我尝试从allshortpath返回的路径中建立新的关系。
$
MATCH (p1:Category {catName: "Main_topic_classifications"}),
(p2:Category {catName: "Monarchs_of_the_Bulgars"}),
path = allShortestPaths((p2)-[:SUBCAT_OF*]->(p1))
FOREACH (s IN rels(path) |
MERGE (startNode(s))-[:NEW_SUBCAT]->(ENDNODE(s)))
但是,当我运行上一个查询时,出现了以下错误:
Neo.ClientError.Statement.SyntaxError: Invalid input '(': expected an identifier character, whitespace, NodeLabel, a property map or ')' (line 5, column 24 (offset: 248))
" MERGE (:startNode(s))-[:NEW_REL]->(:ENDNODE(s)))"
^
答案 0 :(得分:1)
Cypher语言不允许节点模式包含返回节点的函数(即使这样做非常方便)。
此查询(首先创建节点变量s
和e
,以便可以在节点模式中使用该查询)应该为您工作:
MATCH
(p1:Category {catName: "Main_topic_classifications"}),
(p2:Category {catName: "Monarchs_of_the_Bulgars"}),
path = allShortestPaths((p2)-[:SUBCAT_OF*]->(p1))
UNWIND RELATIONSHIPS(path) AS rel
WITH STARTNODE(rel) AS s, ENDNODE(rel) AS e
MERGE (s)-[:NEW_SUBCAT]->(e)