1

In RedisGraph using Cypher/python is there a way to

Merge two nodes and move all the relationships from the old node to the new node ?

I suspect there are no pure Cypher solution... in that case what will be the equivalent atomic operations and how to combine them to achieve MERGE-nodes+rel

neo4j have apoc.refactor.mergeNodes(nodes, options), apoc.refactor.mergeRelationships(rels, options), but that doesn't help me !:( because I'm using RedisGraph.

the problem is that in RG I dont have lower level access to do enumeration/iteration to do this programmatically !!


this worked in one direction I have to apply -> the reverse <- second time.

    MATCH (old)-[r:q]->(from_to)
    WHERE old.val = $old
    MATCH (new) WHERE new.val = $new
    MERGE (new)-[nr2:q]->(from_to)
    SET nr2.val = r.val
    DELETE r

any way to combine it in single query ?

sten
  • 7,028
  • 9
  • 41
  • 63

1 Answers1

2

I think this can be accomplished in pure Cypher:

MATCH (old {val: 'old'})-[e:E]->(old_to)
MERGE (new {val: 'new'})
CREATE (new)-[e2:E]->(old_to)
SET e2.prop1 = e.prop1, [...]
DELETE e

The chief annoyance here is that all of the edge properties (and node properties, if those are also to be migrated) must be set explicitly, as RedisGraph does not currently support setting property maps.

sentientcabbage
  • 466
  • 2
  • 6
  • would this work if the node has both in and out connections – sten Sep 01 '20 at 21:35
  • 1
    The MATCH formulation can be extended to capture incoming connections like so: ```MATCH (old_from)-[e_from]->(old {val: 'old'})-[e_to]->(old_to)``` With the associated changes made to the subsequent CREATE and SET clauses. – sentientcabbage Sep 02 '20 at 13:25