Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

Why isn't the merge command updating the relationship?

Graph Fellow

I originally don't have relationship property so the relationship is shown like below:

  "identity": 631,
  "start": 470,
  "end": 453,
  "type": "coOccur",
  "properties": {


Now I added a confidence to the relationship coOccur, and run this command:

CALL apoc.load.csv('topic_topic_coOccur.csv', {nullValues:['','na',false], sep:'	'}) 
yield map as row ", 
"MATCH (h:Topic{nid: row.start})
MATCH (t:Topic{nid: row.end})
CALL apoc.merge.relationship(h, row.type, {confidence:toFloat(row.confidence)}, {}, t, {}) yield rel
RETURN rel", {batchSize:1000, iterateList:true, parallel:false})

I hope this would just update the empty 'properties' field in the coOccur relationship. However, it didn't. I have to remove all relationships and re-create the relationship. The merge function works well for node property update without recreating the whole node. Why doesn't it work for relationship merging?


Fairly new to Neo4J. Two thoughts:
May be you need to include a WITH before the procudere CALL. Thought I ran into that.
WITH h, t, row.type, row.confidence

However I'm wondering why you don't use Cypher MERGE here and direct the relationship. (That may be something for me to learn 😉

MATCH (h:Topic{nid: row.start})
MATCH (t:Topic{nid: row.end})
MERGE (h) -[:row.type {confidence:toFloat(row.confidence)}-(t)

Taken from:

(charlie:Person {name: 'Charlie Sheen'}),
(oliver:Person {name: 'Oliver Stone'})
MERGE (charlie)-[r:KNOWS]-(oliver)

Direct use of merge is possible, apoc provides more configurations, though not used here much.

I have struggled with relationship property updates using APOC functions myself. You might want to look at your MATCH construction. I would have expected a relationship match, something like (h)-[row.type]->(t). The code sample for apoc.create.setRelProperties() might provide some insights:

MATCH (:Person)-[friends:FRIENDS]->(:Person)
WITH friends, keys(friends) AS keys
CALL apoc.create.setRelProperties(friends,[k in keys | k + "Copy"], [k in keys | friends[k]])
RETURN startNode(rel) AS start, rel, endNode(rel) AS end