Using the latest Neo4j docker container, I'm trying to create a graph for which there are many different node labels and relationships, therefore, I can't hard code each node label and relationship in the create query. I tried to do this programmatically (see code below), the code runs without problems, the nodes are getting created, however the relationships are not (the relationships don't appear in the Neo4j Browser). I made sure that the nodes are create and have the necessary constraints and property indexes. Can anyone please help me understand why the relationships are not added?
Here is the code for adding the relationships: (meta_graph in the first line is a list that contains triplets of subject_node, object_node and relation.)
for subject_node, relation, object_node in meta_graph:
query = """
LOAD CSV WITH HEADERS FROM "file:///input.csv" AS row
FIELDTERMINATOR ';'
MATCH (s:%s {id: row.id_subj, title: \"row.subject\"})
MATCH (o:%s {id: row.id_obj, title: \"row.object\"})
MERGE (s)-[r:%s {id: toInteger(row.id_relation)]->(o)
""" % (subject_node, object_node, relation)
_driver.execute_query(query, database_="neo4j")
Can you share the query you use in the browser? Did you explicitly return the relationships in your browser query?
BTW- you can use single quotes to enclose a string in cypher, so you can use them if you don't want to except your double quotes in your cypher string.
This is the query that I used to check for the relations:
MATCH ()-[r]->()
RETURN r;
It returns (no changes, no records). In order to make sure that it can really MATCH with the nodes, I manually selected some labels of the meta_graph list, hardcoded the labels in the query, and it returned the target nodes.
Also on the left-hand side screen of the browser, it doesn't show any info. about the relationships, here is a screenshot:
For the Node labels section, it shows the total number of the nodes and their labels.
The fact that the browser is showing there is no relationships in the database AND your simple query above returns zero results, I suspect the relationships were not created.
Can you run the creation query above in the browser to see what happens? Can you try with a small sample of the rows?
Exactly.. The error was that I didn't cast the nodes ids and it was faulting silently.. I fixed it by casting the id of Nodes s and o .. Thanks a lot @glilienfield!