问题
Is it possible to clone arbitrary nodes and relationships in a single Cypher neo4j 2.0 query? 'Arbitrary' reads 'without specifying their labels and relationship types'. Something like:
MATCH (node1:NodeType)-[e]->(n)
CREATE (clone: labels(n)) set clone=n set clone.prop=1
CREATE (node1)-[e1:type(e)]->(clone) set e1=e set e1.prop=2
is not valid in Cypher, so one cannot simply get labels from one node or relationship and assign them to another, because labels are compiled into the query literally.
Sure, labels and relation types are important for MATCH and WHERE for producing effective query plan, but isn't CREATE making another case?
回答1:
The easiest way to clone parts of a graph is to use the dump command in Neo4j shell. dump
generates cypher create
statements from your return
clauses. The result of dump can be appied to the graph database to create clones.
来源:https://stackoverflow.com/questions/20779579/clone-nodes-and-relationships-with-cypher