cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

3 relationships that I didn't create appeared in the database

11li
Node Clone

Hi, everyone!
I load some csv files to create nodes and relationships.
While I only create 7 relationships. The schema shows 10 relationships.
3X_9_a_9ad9a4a96ccef098621fa1b730ea58d4503fa5f1.png
3X_6_c_6c9acf1f519c642d9832d6d6b5f5ccdfa5772d3c.png

Process:
1.CREATE CONSTRAINT

CREATE CONSTRAINT constraint_nav IF NOT EXISTS ON (n:Nav) ASSERT n.nav_id IS UNIQUE;
CREATE CONSTRAINT constraint_nav_tech IF NOT EXISTS ON (n:NavTech) ASSERT n.navtech_id IS UNIQUE;
CREATE CONSTRAINT constraint_dev IF NOT EXISTS ON (n:Device) ASSERT n.dev_id IS UNIQUE;
CREATE CONSTRAINT constraint_sensor_type IF NOT EXISTS ON (n:SensorType) ASSERT n.sensortype_id IS UNIQUE;

2.create nodes.

LOAD CSV WITH HEADERS FROm 'file:///nav.csv' AS line
MERGE (n:Nav {nav_id: line.nav_id}) SET n += line

LOAD CSV WITH HEADERS FROm 'file:///navtech.csv' AS line
MERGE (n:NavTech {navtech_id: line.navtech_id}) SET n += line

LOAD CSV WITH HEADERS FROm 'file:///dev.csv' AS line
MERGE (n:Device {dev_id: line.dev_id}) SET n += line

LOAD CSV WITH HEADERS FROm 'file:///SensorType.csv' AS line
MERGE (n:SensorType {sensortype_id: line.sensortype_id}) SET n += line

3.create relationships.

LOAD CSV WITH HEADERS FROm 'file:///r_nav_dev.csv' AS line
MATCH (a:Nav {nav_id: line.nav_id})
MATCH (b:Device {dev_id: line.dev_id})
MERGE (a)-[:use]->(b)

LOAD CSV WITH HEADERS FROm 'file:///r_nav_navtech.csv' AS line
MATCH (a:Nav {nav_id: line.nav_id})
MATCH (b:NavTech {navtech_id: line.navtech_id})
MERGE (a)-[:adopt]->(b)

LOAD CSV WITH HEADERS FROm 'file:///r_navtech_dev.csv' AS line
MATCH (a:NavTech {navtech_id: line.navtech_id})
MATCH (b:Device {dev_id: line.dev_id})
MERGE (a)-[:use]->(b)

LOAD CSV  FROM 'file:///r_navtech_navtech_use.csv' AS line
With line
Skip 1
MATCH (a:NavTech {navtech_id: line[0]})
MATCH (b:NavTech {navtech_id: line[2]})
MERGE (a)-[:use]->(b)

LOAD CSV FROM 'file:///r_navtech_navtech_subclassof.csv' AS line
With line
Skip 1
MATCH (a:NavTech {navtech_id: line[0]})
MATCH (b:NavTech {navtech_id: line[2]})
MERGE (a)-[:subclass_of]->(b)


LOAD CSV FROM 'file:///r_navtech_navtech_sameas.csv' AS line
With line
Skip 1
MATCH (a:NavTech {navtech_id: line[0]})
MATCH (b:NavTech {navtech_id: line[2]})
MERGE (a)-[:same_as]->(b)

LOAD CSV WITH HEADERS FROm 'file:///r_sensortype_dev.csv' AS line
MATCH (a:SensorType {sensortype_id: line.sensortype_id})
MATCH (b:Device {dev_id: line.dev_id})
MERGE (b)-[:subclass_of]->(a)

Files:
dev.txt (750 Bytes)
nav.txt (32 Bytes)
navtech.txt (1.2 KB)
SensorType.txt (201 Bytes)
r_nav_dev.txt (458 Bytes)
r_nav_navtech.txt (682 Bytes)
r_navtech_dev.txt (257 Bytes)
r_navtech_navtech_sameas.txt (77 Bytes)
r_navtech_navtech_subclassof.txt (663 Bytes)
r_navtech_navtech_use.txt (199 Bytes)
r_sensortype_dev.txt (691 Bytes)

Version: 4.4.5
Edition: Community
Name: neo4j
1 REPLY 1

@11li

This seems to be a known neo4j issue, see here Bug - db.schema() returning non-existent relationships · Issue #9726 · neo4j/neo4j · GitHub.

So, alternatively to this procedure, you can use the apoc.meta.graph procedure,
which through a sample of nodes, it get rid of false positive extra relationships.

As explained here,
you can customize the sample size to speed up the query (but with a relatively small number the probability of having false positives is greater).