Showing results for 
Search instead for 
Did you mean: 

How to get rid of not matching elements

Node Clone

Using Comunity edition 4.3.2 with apoc
I have a question that I wasn't able to solve.

I am importing some data from a CSV file.

In the first round I imported all data that match some business condition. On 900 input lines, I imported 841.

But the other 59 are lost.

So I make another round with the same input file with the following statements:

MATCH (p:Product {ownerid: row.ProductCode})-[:SOLD_BY]->(customer)

My idea was to filter on

WHERE p.ownerid IS NULL
   MERGE (p:BadProduct {... properties})

I expected to have a return count of 59, but instead it was 0

the same happened if I use WHERE p IS NULL

Instead, if I use OPTIONAL MATCH it CREATEs 900 BadProduct nodes

Can someone help or explain how to filter on UNMATCHED conditions (or how to get rid of excluded lines on IMPORT CSV)

Thank you



Hello @p.dipietro

You can not match anything on null, null means nothing, not exists at all, null is not a value.
So therefore your MATCH clause will match nothing.

If you do SET p.ownerid = null you destroy the ownerid property from the node and therefore you cannot match on it anymore.

The origin of your lost lines must be in the csv file or in the importation Cypher you used to import them.

Node Clone

Hi @tard.gabriel,

Yes, you are absolutely correct about NULL. Maybe there was a type in the query in the previous example.
So, I try to reformulate the question.

I have a set of data coming from a CSV file.

The first row match some conditions and then is added to the DB as a good node.

MATCH (prov:Provider {name: row.provider}
    MERGE (n:Product {})-[:SOLD_BY]->(prov)

but if the second row doesn't match the first condition I want to add it to the set of BAD nodes

MATCH (prov:Provider {name: row.provider}
    WHERE prov IS NULL
    MERGE (n:BADProduct {})

Is there a way I can use to solve this problem?