Reputation: 535
We are using Neo4j 2.1.4 Community edition.
We are facing some issues in getting the specific paths in neo4j.
Below is the csv file used.
In graph database we are creating Product, Company,Country and Zipcode nodes along with the relationship type as ‘MyRel’ at each level.In the above data we wanted to differentiate each path ,
that is
Mobile, Google,US,88888 -- as path1
Mobile,Goolge,US -- as path2
Mobile,Goolge -- as path3
That’s why we created one more column called Path
in data file and maintaining the Path
value as a relatioship property. So whenever someone wants to see the different paths he can query based on Relationship property either 1 or 2 or 3. For eample , whenever we query for the relationship property, we should get Mobile,Google ,US
But whenever I do this , in graph it is creating dummy node for Country and Zipcode. This is due to in 2nd and 3rd row the zip and country values are empty(null).
Query used:
LOAD CSV WITH HEADERS FROM "file:C:\\WorkingFolder\\Neo4j\\EDGE_Graph_POC\\newdata\\trial1.csv " as file
MERGE (p:Product {Name:file.Product})
MERGE (comp:Company {Name:file.Company})
MERGE (c:Country {Name:file.Country})
MERGE (zip:Zipcode{Code:file.Zipcode})
CREATE (p)-[:MyRel{Path:file.Path}]->(comp)-[:MyRel{Path:file.Path}]->(c)-[:MyRel{Path:file.Path}]->(zip)
Resultant graph:
So how can I avoid creating dummy nodes ?
Is there any better alternative option to get the proper path?
Thanks,
Upvotes: 1
Views: 97
Reputation: 41706
You can filter them out with
WHERE file.Country <> '' and file.Zipcode <> ''
and split up your CREATE e.g.
CREATE (p)-[:MyRel{Path:file.Path}]->(comp)
WHERE file.Country <> '' and file.Zipcode <> ''
MERGE (c:Country {Name:file.Country})
MERGE (zip:Zipcode{Code:file.Zipcode})
CREATE (comp)-[:MyRel{Path:file.Path}]->(c)-[:MyRel{Path:file.Path}]->(zip)
Upvotes: 0
Reputation: 2272
First, A simple solution is to follow the LOAD CSV query with others that clean up your graph. Run the queries
MATCH (zip:Zipcode { Code : ''})<-[r]-()
DELETE zip, r
and
MATCH (c:Country { Name : ''})<-[r]-()
DELETE c, r
You will then have the graph you desire.
Upvotes: 1