Constraint issue

Hi - i am a newbie with Neo4J so apologies in advance.

I am developing a java app that sucks model repository knowledge out of a rhapsody model into Neo4J (v3.5.12) for subsequent analysis.
Rhapsody (from a simple single model perspective) guarantees model element uniqueness through an associated GUID.
All nodes have label "Element" but when i am loading the artefacts into Neo4J (via LOAD CSV) i am allocating each node multiple labels based upon where within the Rhapsody type hierarchy the element is situated (so for example a class node may be decorated with labels :Element:ModelUnit:Classifier:Class).
Below is an example of the cypher query i am running using the run method on the session class.

LOAD CSV WITH HEADERS FROM 'file:///C:\\temp\\Class.csv' AS row MERGE (n:Element:ModelUnit:Classifier:Class { ElementGuid: row.ElementGuid}) ON MATCH SET n.OwnerElementMetaClass=row.OwnerElementMetaClass, n.ElementIsReactive=row.ElementIsReactive ON CREATE SET n.ElementGuid=row.ElementGuid, n.OwnerElementMetaClass=row.OwnerElementMetaClass, n.ElementIsReactive=row.ElementIsReactive

My understanding is that using MERGE should take care of both when the node does not already exist and when it does.
Specifically because I am MERGING on label 'Element' (the base type) and discriminating using the unique ElementGuid property then i would have thought that I should end up with each node having a unique elementGuid.

However when i execute
it complains that the constraint cannot be asserted because nodes exist having the same elementGuid property.

I am wondering if it is because in the MERGE I am already allocating multiple labels?

Any thoughts and observations would be most welcome


That sounds likely.

MERGE is like a MATCH, and if the match fails, a CREATE. If you may already have the node in your db, but it may not have all the labels, then you should only MERGE on the set of labels that lets you uniquely identify the node (in this case, :Element), and then SET the rest of the labels.

Yes that is my chief suspect at the moment - I'll try it and give some (hopefully +ve) feedback

Yes that was the problem.