用于将关系加载到neo4j中的Cypher代码忽略csv列中的数据

时间:2015-07-22 14:07:42

标签: neo4j cypher

我正在加载关系到neo4j。这对我很好:

USING PERIODIC COMMIT 500 LOAD CSV WITH HEADERS FROM "<link to topic relationships.csv>" AS csvLine MATCH (work:Work {id: csvLine.recordIdentifier}),(topic:Subject {topic: csvLine.topicID}) CREATE work-[:ISABOUT]->topic;

但这种非常相似的情况对我不起作用:

neo4j-sh (?)$ LOAD CSV WITH HEADERS FROM "<link to AuthorRel.csv on GitHub>" AS csvLine MATCH (c:Creator { name: csvLine.creatorID}), (w:WORK { id: csvLine.recordIdentifier}) CREATE c-[:CREATED]->w;
+--------------------------------------------+
| No data returned, and nothing was changed. |
+--------------------------------------------+
493 ms
neo4j-sh (?)$ 

这部分有效,

neo4j-sh (?)$ LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/HeardLibrary/graphs-without-ontologies/master/GraphData/AuthorRel.csv" AS csvLine return csvLine;

这是有效的

neo4j-sh (?)$ LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/HeardLibrary/graphs-without-ontologies/master/GraphData/AuthorRel.csv" AS csvLine MATCH (w:Work { id: csvLine.recordIdentifier}) return w;

但是当我尝试MATCH时它会崩溃:创作者名称:

LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/HeardLibrary/graphs-without-ontologies/master/GraphData/AuthorRel.csv" AS csvLine MATCH (c:Creator { name: csvLine.creatorID}) return c; 

我收到有关NULL值的错误消息,所以我尝试了这个(来自Create Neo4j database using CSV files):

  neo4j-sh (?)$ USING PERIODIC COMMIT 500 LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/HeardLibrary/graphs-without-ontologies/master/GraphData/AuthorRel.csv" AS csvLine MATCH (w:WORK { name: csvLine.recordIdentifier}) MERGE (c:Creator { name:  coalesce(csvLine.creatorID, "No Name")}) CREATE (c)-[:Created]->(w);
    +-------------------+
    | No data returned. |
    +-------------------+
    Nodes created: 1
    Relationships created: 52
    Properties set: 1
    Labels added: 1
    998 ms

    neo4j-sh (?)$ match (c)-[r:Created]->(w) return c,r,w limit 10;

    | Node[278478]{name:"No Name"} | :Created[26273]{} | Node[278029]{name:"oai:dash.harvard.edu:1/2031670"} |
    | Node[278478]{name:"No Name"} | :Created[26272]{} | Node[278030]{name:"oai:dash.harvard.edu:1/2019322"} |
    | Node[278478]{name:"No Name"} | :Created[26275]{} | Node[278031]{name:"oai:dash.harvard.edu:1/2031713"} |
    | Node[278478]{name:"No Name"} | :Created[26274]{} | Node[278031]{name:"oai:dash.harvard.edu:1/2031713"} |
    | Node[278478]{name:"No Name"} | :Created[26277]{} | Node[278031]{name:"oai:dash.harvard.edu:1/2031713"} |
    | Node[278478]{name:"No Name"} | :Created[26276]{} | Node[278031]{name:"oai:dash.harvard.edu:1/2031713"} |
    | Node[278478]{name:"No Name"} | :Created[26279]{} | Node[278032]{name:"oai:dash.harvard.edu:1/2026618"} |
    | Node[278478]{name:"No Name"} | :Created[26278]{} | Node[278033]{name:"oai:dash.harvard.edu:1/2027194"} |
    | Node[278478]{name:"No Name"} | :Created[26281]{} | Node[278033]{name:"oai:dash.harvard.edu:1/2027194"} |
    | Node[278478]{name:"No Name"} | :Created[26280]{} | Node[278034]{name:"oai:dash.harvard.edu:1/2027199"} |

未从CSV中提取姓名数据。请指教。

1 个答案:

答案 0 :(得分:0)

您似乎在“无法正常工作”的情况下输入错字。 WORK节点的属性名称应为name,而不是id