cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Why isn't the merge command updating the relationship?

lingvisa
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?

3 REPLIES 3

Hi,
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:

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

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]])
YIELD rel
RETURN startNode(rel) AS start, rel, endNode(rel) AS end