0
votes

I have entered a query:

LOAD CSV FROM "file:///E:/HVR_1.csv" AS row
MERGE (u:Source {id: toInt(row[0])})
MERGE (t:Target {id: toInt(row[1])})
MERGE (u)-[:LinkTo]->(t)

I want to create a unique node with incoming and outgoing links. I don't know where I had gone wrong. As it can be found, there are two nodes with value "4". One is for outgoing and another for incoming. It happens the same with other nodes too. I want to have a single node with all incoming and outgoing relations. Can anyone please help me?

Datasets looks like this

In this image there are nodes with same values

1

1 Answers

1
votes

I think the problem is you are using two different node labels in your query, :Source and :Target. The uniqueness guaranteed in the MERGE is a node with the given label with the given property, so if you have a :Source node with a given id, and you try to merge a :Target node with the same id, it will create a separate node, since the labels are different.

So as it looks like nodes in this import ought to be using the same labels, choose something that reflects the role of that particular node in your overall database, not in the context of the import operation.

Also, for the sake of speeding up this import, I would add a uniqueness constraint on the id property for whatever node label you end up using.