Okay, let's go through that query.
MERGE (language:TaxonomyLanguage { name: line.name})
ON MATCH SET language.name = line.name
ON CREATE SET language.name = line.name
This will look for an existing :TaxonomyLanguage node with the given name, and if it doesn't exist, create it.
Since you're already merging the node by its name property, the property is already set, and neither of those followup ON MATCH SET or ON CREATE SET are needed, you can drop both of those.
MERGE (parentLanguage:TaxonomyLanguage { name: coalesce(line.parent,"receipe")}) //assign root node name here from database
This finds an existing :TaxonomyLanguage node with the given name from line.parent
(or uses "receipe" for the name if it doesn't exist).
MERGE (language)-[:IN_Language]->(t1:Taxonomy)
You merge a relationship [:IN_Language] between the language
node and some :Taxonomy node. Note that t1
hasn't been used yet, this is a brand new variable, so this will match to a :Taxonomy node if such a pattern already exists, otherwise it will create a new relationship to a brand new :Taxonomy node (with no proeperties), and I'm not sure if this is doing what you want.
MERGE (t1)-[:HAS_EXTERNAL_REF]->(:ExternalReference{source:"AEM", externalId:"23423d42", lastUpdated: datetime()})
From that potentially new t1:Taxonomy node, you MERGE this pattern. Note that if such a pattern doesn't exist, it may create a brand new :ExternalReference node with those properties. If there is already such a node in your graph (but not attached to the t1 node) it won't be used since you didn't MATCH to it first.
MERGE (parentLanguage)-[:IN_Language]->(t2:Taxonomy)
Here you are first checking if the parentLanguage
node from earlier is attached to a :Taxonomy node by the given relationship. If such a pattern doesn't already exist in your graph, then a brand new :Taxonomy node (with no properties) will be created and used for this pattern.
MERGE (t1)-[:IS_CHILD_OF]->(t2)
This will merge that relationship between the two (potentially newly-created) t1 and t2 nodes.
Anything wrong with this so far?
If you wanted two separate No-bake nodes, one attached to each parent, then you shouldn't MERGE on language
.
Instead you should MERGE the parent
first, and then MERGE the language
node into the parent along with the relationship:
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///testtagfinal.csv' AS line
MERGE (parentLanguage:TaxonomyLanguage { name: coalesce(line.parent,"receipe")}) //assign root node name here from database
MERGE (parentLanguage)-[:IN_Language]->(t2:Taxonomy)
MERGE (t1:Taxonomy)-[:IS_CHILD_OF]->(t2)
MERGE (language:TaxonomyLanguage { name: line.name})-[:IN_Language]->(t1)
MERGE (t1)-[:HAS_EXTERNAL_REF]->(:ExternalReference{source:"AEM", externalId:"23423d42", lastUpdated: datetime()})
This starts with the parentLanguage, merging that if it doesn't already exist, merging that to its :Taxonomy (creating if it doesn't already exist), matching to or creating a child :Taxonomy from the parent taxonomy, and then merging the language
of the given name that must be in that child taxonomy.
So looking at the No-bake lines in the CSV, we're starting from two parent languages, technique and workflow, finding their taxonomy languages, and the children of those, then for each of those child :Taxonomy nodes merging the pattern to No-bake :TaxonomyLanguage nodes. Since we're merging the pattern from t1
, and not merging language
alone, a new node will be created for each.