问题
i am new to neo4j and cypher , i need to create the opposite of all the edges of the graph but i need that the opposites edges to have the same type of the original edges
for illustration the opposite of (a)-[:sometype]->(b)
would be (b)-[:sometype]->(a)
i know that it is very easy to create the opposite of all the edges by just tapping this command
match (a)-[]->(b) create (b)-[]->(a)
but as i have already said i need the created edge to have the same type of the original edge
thank you
回答1:
According to this comment in an open question in neo4j's Github this is not possible yet.
As said by InverseFalcon in this comment, you can use APOC Procedures to achieve this goal as described in this post from Mark Needham blog.
Fist, install Apoc Procedures. After this, e.g.:
CREATE (a)-[:sometype]->(b)
//Match...
MATCH (a)-[r]->(b)
WITH r, a, b
// and use apoc.create.relationship to achieve your goal...
CALL apoc.create.relationship(b, TYPE(r), {}, a) YIELD rel
RETURN rel
Tested here:
来源:https://stackoverflow.com/questions/43594138/neo4j-create-the-opposite-edge