Search code examples
neo4jcypheroncreaterelationships

Neo4J RelationShips MERGE ONCREATE ONMATCH


Is there a solution to distinct ON CREATE and ON MATCH on relationship MERGE ?

For example :

USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM 'http://ip/myfile.csv' AS row
MATCH (source:Ticket {Id: toInt(row.idticket)})
MATCH (target:User {Id: toInt(row.iduser)})
MERGE (source)-[rel:`AskBy` {}]->(target);

To do something like this

USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM 'http://ip/myfile.csv' AS row
MATCH (source:Ticket {Id: toInt(row.idticket)})
MATCH (target:User {Id: toInt(row.iduser)})
MATCH (source)-[rel:`AskBy` {}]->(target);
ON CREATE SET (source)-[rel:`AskBy` {createDate: timespan()}]->(target)
ON MATCH SET (source)-[rel:`AskBy` {updateDate: timespan()}]->(target)

I want to distinct creation date and update date of relationship

Thanks


Solution

  • You just need to set the property:

    MATCH (source:Ticket {Id: toInt(row.idticket)})
    MATCH (target:User {Id: toInt(row.iduser)})
    MERGE (source)-[rel:AskBy]->(target)
    ON CREATE SET rel.createDate = timestamp()
    ON MATCH SET rel.updateDate = timestamp();