when loading csv in neo4j do not create all the relationships

176 Views Asked by At

good to all please help me with this problem :D

when I execute my query:

USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM "file:///Create_all.csv" AS row
MATCH(x:Category{uuid:row.uuid_category}) 
MERGE (t:Subscriber{name:row.name_subscriber, uuid:row.uuid_subscriber})
CREATE (n:Product{name: row.name_product, uuid: row.uuid_product}),
(Price:AttributeValue{name:'Price', value: row.price_product}),
(Stock:AttributeValue{name:'Stock', value: row.stock_product }),
(Style:AttributeValue{name:'Style', value: 'Pop Art'}),
(Subject:AttributeValue{name:'Subject', value: 'Portrait'}),
(Originality:AttributeValue{name:'Originality', value: 'Reproduction'}),
(Region:AttributeValue{name:'Region', value: 'Japan'}),
(Price)-[:IS_ATTRIBUTEVALUE_OF]->(n),
(Stock)-[:IS_ATTRIBUTEVALUE_OF]->(n),
(Style)-[:IS_ATTRIBUTEVALUE_OF]->(n),
(Subject)-[:IS_ATTRIBUTEVALUE_OF]->(n),
(Originality)-[:IS_ATTRIBUTEVALUE_OF]->(n),
(Region)-[:IS_ATTRIBUTEVALUE_OF]->(n)
  WITH (n),(t),(x)     

create  (n)-[:OF_CATEGORY]->(x)
create (t)-[:SELLS]->(n)

The format of my csv is as follows:

I have 4 categories, 30 products and 10 subscriber creates me:

Added 164 labels, created 164 nodes, set 328 properties, created 184 relationships, completed after 254 ms.

I verify the result with:

MATCH p=()-[r:OF_CATEGORY]->() RETURN count(r)

There are 23 relationships created, however, the remaining 7 relationships were not created.

please guide me with the query should be created all relationships in this case would be 30 relationships products with categories

1

There are 1 best solutions below

0
On

The critical part is MATCH(x:Category{uuid:row.uuid_category})

If that match fails for a row, the row will be wiped out and none of the other operations for that row will execute.

Since your input consists of 4 of the same category (let's call them 1,2,3,and 4) repeating 7 times (for 28 rows total so far), and then two of those occurring one more time each (2 times if both successful, for a total of your entire 30 rows), it would make sense if some of your matches are failing, with :Category nodes with some of those uuid_category properties not actually being present in the graph.

Of those uuids (1,2,3, and 4), only 1 and 2 occur at the end (so occurring across 8 rows for these two, as opposed to 7 times for uuids 3 and 4). It would make sense if either uuid 3 or 4 doesn't have a corresponding node in the graph. That would get us 1 * 7 + 2 * 8 = 23, which is the number of relationships that your query is creating.

So there is no :Category node for the uuid_category ending with either 3 or 4.

Check your graph against your data to confirm.