Neo4j - Unable to load Relations from csv

不打扰是莪最后的温柔 提交于 2019-12-08 12:18:52

问题


I am trying to load the data from the csv and display the nodes along with the relations as the graph in Neo4j. I am able to load the entity1 and entity2 in Neo4j, but unable to load the relations from the csv. My csv file looks like this

Below is my CYPHER Code

LOAD CSV WITH HEADERS FROM "file:////csvFiles/Fraud_Triplets_Neo4j.csv" AS csvLine
MERGE (a:Subject {
 Object1:csvLine.Entity1
,display:csvLine.Entity1
 });


LOAD CSV WITH HEADERS FROM
"file:////csvFiles/Fraud_Triplets_Neo4j.csv" AS csvLine 
MERGE (b:Object {  Object2:csvLine.Entity2 ,display:csvLine.Entity2  });

  LOAD CSV WITH HEADERS FROM "file:////csvFiles/Fraud_Triplets_Neo4j.csv" AS csvLine
MATCH (a:Subject { Object1: csvLine.Entity1})
MATCH (b:Object { Object2: csvLine.Entity2})
MERGE ((a) -[:Relation{r:csvLine.Relation}]-> (b))

I am getting

Kindly let me know, how should i specify relation from csv file.


回答1:


I don't know if I understood you question completely, but I guess you are trying to create the relationship with types based on column "Relation" of your .CSV file.

You can do it installing APOC Procedures and using apoc.create.relationship procedure.

Also, your Cypher query can be simplified. You don't need to call LOAD CSV 3 times. Try something like this:

LOAD CSV WITH HEADERS FROM "file:////csvFiles/Fraud_Triplets_Neo4j.csv" AS csvLine

MERGE (a:Subject {
    Object1:csvLine.Entity1,
    display:csvLine.Entity1
});

MERGE (b:Object {
    Object2:csvLine.Entity2,
    display:csvLine.Entity2
});

CALL apoc.create.relationship(a, csvLine.Relation, {}, b) YIELD rel

RETURN *

Note: Remember to install APOC Procedures based on the version of Neo4j you are using. Take a look in the Version Compatibility Matrix.



来源:https://stackoverflow.com/questions/46406004/neo4j-unable-to-load-relations-from-csv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!