Change relation type based on relation property
bent.s.lund@gmail.com
Hi, DataImporter is not dynamically creating relation types based on the input-file but allows a fixed relation type "RelatatesTo" to have properties.
I have imported all my relations as "RelatesTo" and a property REF_TYPE holds the real relation type. Is there a easy way to change the relation type dynamically based on the relations property REF_TYPE?
bent.s.lund@gmail.com
I am thinking something like this but I am not familiar enough with cypher:
match(t1:Tag)-[rel:RelatesTo]->(t2:Tag)
yield rel
call apoc.refactor.setType(rel, rel.REF_TYPE)
Any suggestions are welcome
Gregory King
bent.s.lund@gmail.com: Hi, yes something like this should work.
For the purpose of a minimal working illustration, here are three
CREATE
statements that generate three relationships of the same type
but that all have their true type encoded in a property named type
.CREATE ()-[:REL_TYPE {type: 'a'}]->()
CREATE ()-[:REL_TYPE {type: 'b'}]->()
CREATE ()-[:REL_TYPE {type: 'c'}]->()
The following apoc refactor procedure call will change the
REL_TYPE
s to be the respective types a
, b
and c
encoded in the property for that relationship.MATCH ()-[r:REL_TYPE]->()
CALL apoc.refactor.setType(r,r.type) YIELD output
RETURN output
bent.s.lund@gmail.com
Gregory King: Thanks, this was exactly what I was trying to achive. Very elegant, now I can overcome this limitation of the DataImporter!