0
votes

In Neo4j Cypher using neo4j-shell I can relationships to a single node based on a property like this:

match (p:Taxon{taxId:'9605'}),(t:Taxon{parentTaxId:p.taxId}) 
create unique (p)-[:PARENT_OF]->(t);

With the taxId set in p it runs as expected and relationships are created as required. However when I try to apply it to all nodes by changing the query to:

match (p:Taxon),(t:Taxon{parentTaxId:p.taxId}) 
create unique (p)-[:PARENT_OF]->(t);

I get an error:

NotFoundException: Unknown identifier t.

I do not understand why t is now invalid. Am I missing something obvious?

1
Ah, I understand what is happening. The second query is not working as there are taxa that have no children. In this case t is not found and so there is not a t to create a relationship to. Is it possible to put something in a where clause for detecting if t is not found?Daniel Vaughan
something like: match (p:Taxon),(t:Taxon{parentTaxId:p.taxId}) where not(t is null) create unique (p)-[:PARENT_OF]->(t);Daniel Vaughan
also tried: \match (t:Taxon),(p:Taxon{taxId:t.parentTaxId}) where HAS(t.parentTaxId) create unique (p)-[:PARENT_OF]->(t);Daniel Vaughan

1 Answers

1
votes

I think you need to break it into the WHERE clause:

MATCH (p:Taxon),(t:Taxon)
WHERE t.parentTaxId=p.taxId 
CREATE UNIQUE (p)-[:PARENT_OF]->(t);