Это должно работать:
MATCH (p1:Category)
WHERE p1.category IN ["Health", "History", "Humanity"]
MATCH
(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)
[ОБНОВЛЕНО]
Если p1
также должен быть непосредственным подкадром Top_Main_Classification
, то вы можете сделать это:
MATCH (p1:Category)-[:SUBCAT_OF]->(main:Category {catName: "Main_topic_classifications"})
WHERE p1.category IN ["Health", "History", "Humanity"]
MERGE (p1)-[:NEW_SUBCAT]->(main)
MATCH
(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)