Database Reference
In-Depth Information
The behavior of
MERGE
is that it either matches the whole pattern, or it creates the whole
pattern. It will not partially use existing patterns—it's all or nothing.
MERGE
is accompanied and followed with
ON CREATE
and
ON MATCH
. These allow us
to perform additional changes to the nodes, properties, and relationship depending upon
the result of the
MERGE
command.
For example, the preceding
LOAD CSV
command can be re-written as:
LOAD CSV WITH HEADERS FROM "$NEO4J_HOME/neo4j-import.csv"
as csv
MERGE (cinestars:Cinestar {Name : csv.Name})
ON CREATE SET cinestars.WorkedAs = split (csv.WorkedAs,",");
The preceding command will load the data and set the properties of the node only if it is
created. No changes will be performed in case the node already exists.
Note
LOAD CSV
only works with Cypher 2.1 and above. Check the version of kernel by execut-
ing
dbinfo -g Kernel KernelVersion
on
neo4j-shell
(in Unix) or
neo4jshell
(in Windows) and if required upgrade or try appending Cypher 2.1 before
your
LOAD CSV
statement.