1

So I have a use case where periodically I update my graph with complex subgraphs. In these subgraphs there will be nodes which are already in the graph, and nodes which are new. I had thought that Merge should do this, but in fact merge appears to create a new node even if there was already a unique node, if the property specifications are not identical.

E.g. on the Neo4j Console, Suppose that I do:

MERGE (a:Crew {name:'Neo', occupation:'The One'})
MERGE (a:Crew {name:'Adam', occupation:'Mechanic'})
CREATE UNIQUE (a)-[r:KNOWS]->(b)
RETURN *

That causes the console to create a second version of Neo, rather than to simple attach the occupation to the existing version.

enter image description here

This happens even if you use:

CREATE CONSTRAINT ON (p:Crew) ASSERT p.name IS UNIQUE

Although now it just refuses to create anything since it won't match the two neo's as one property is blank, and it isn't allowed to create a new node either.

2 Answers 2

2

It creates a second version because it's not unique. You're specifying an additional property, "occupation", which doesn't currently exist in the original Neo node, so it doesn't find a match and therefore creates a new node.

2

Use this instead:

MERGE (a:Crew {name:'Neo'}) ON CREATE SET a.occupation='The One'
MERGE (a:Crew {name:'Adam'}) ON CREATE SET b.occupation='Mechanic'
MERGE (a)-[r:KNOWS]->(b)
RETURN *

See also: http://docs.neo4j.org/refcard/2.1/

2
  • Yes, I appreciate this, but a given user is not guaranteed to know whether a field is filled out or not.
    – phil_20686
    May 27, 2014 at 9:37
  • In our given use case, for example, there are several message standards from which we are harvesting information, and they share some fields but not others.
    – phil_20686
    May 27, 2014 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.