# Inserting a Relationship Post Database Setup

**URL:** <https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256>\
**Category:** Import / Export\
**Tags:** import\
**Created:** [June 22, 2019, 1:22pm UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256 "2019-06-22T13:22:19Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![wilsomrm2](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/wilsomrm2/32/5351_2.png) [@wilsomrm2](https://community.neo4j.com/u/wilsomrm2)\
**Post date:** [June 22, 2019, 1:22pm UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/1 "2019-06-22T13:22:19Z")

</div>

Hi I am new to Neo4j but have searched and tried to come to a resolution for a week now with no success. I have a DB with the OffShore\_Leaks in it. I have imported the Nodes of Bahamas\_Leaks and am trying to get the Relationships of Bahamas inserted.

I have filtered and created a filtered relationship with a header  
node\_1,rel\_type,node\_2,sourceID,valid\_until,start\_date,end\_date  
23000001,intermediary\_of,20000035,Bahamas Leaks,The Bahamas Leaks data is current through early 2016.,,  
23000001,intermediary\_of,20000033,Bahamas Leaks,The Bahamas Leaks data is current through early 2016.,,  
23000001,intermediary\_of,20000041,Bahamas Leaks,The Bahamas Leaks data is current through early 2016.,,  
....

And have checked that these IDs exist in the Intermediary and Entity Nodes.

I have created a number of Cyphers to import as the bulk importers must have nodes and seem to be mainly to instantiate DB only.

LOAD CSV WITH HEADERS FROM "http://IP\_ADDRESS/bulk/import/intermediary\_of.csv" AS row  
WITH row WHERE row.rel\_type = "intermediary\_of"  
MATCH (n1:Node) WHERE n1.node\_id = row.node\_1  
MATCH (n2:Node) WHERE n2.node\_id = row.node\_2  
CREATE (n1)-[:INTERMEDIARY\_OF]-\>(n2);

Syntactically this looks to be correct  
when run via the Desktop I get "(no changes, no records)".

Going in circles on this one.

---

<div class="post-metadata">

**Author:** ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)\
**Post date:** [June 22, 2019, 3:55pm UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/2 "2019-06-22T15:55:37Z")

</div>

Hi,

Looks like you imported bahamas\_leaks\_nodes only. Did you import bahamas\_leaks\_intermediary?

MATCH (n1:Node) WHERE n1.node\_id = "23000001" is failing as this id does not exist in bahamas\_leaks\_nodes. This id exists in bahamas\_leaks\_intermediary.

Here is the schema that I used for offshore\_leaks:

 ![sgp_75_1](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/2X/8/8d86014375688a6d016287ee2237e7e03fe77a6c.png)

---

<div class="post-metadata">

**Author:** ![wilsomrm2](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/wilsomrm2/32/5351_2.png) [@wilsomrm2](https://community.neo4j.com/u/wilsomrm2)\
**Post date:** [June 22, 2019, 5:26pm UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/3 "2019-06-22T17:26:28Z")

</div>

I have the correct scheme and all the data in from offshore\_leaks, I have the nodes from bahamas\_leaks and can search and find them individually,

I have changed my cypher and gone to the command line, hoping to get a better error code.

neo4j\> LOAD CSV WITH HEADERS FROM "http://IP\_ADDRESS/bulk/import/intermediary\_of.csv" AS row  
WITH row WHERE row.rel\_type = "intermediary\_of"  
MATCH (n1:Node) WHERE n1.node\_id = row.node\_1  
MATCH (n2:Node) WHERE n2.node\_id = row.node\_2  
CREATE (n1)-[:INTERMEDIARY\_OF]-\>(n2);

**Connection to the database terminated. This can happen due to network instabilities, or due to restarts of the database**

Everytime I run this cypher the database dies.

---

<div class="post-metadata">

**Author:** ![wilsomrm2](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/wilsomrm2/32/5351_2.png) [@wilsomrm2](https://community.neo4j.com/u/wilsomrm2)\
**Post date:** [June 22, 2019, 5:27pm UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/4 "2019-06-22T17:27:44Z")

</div>

To note I also changed the import to be file:/// with the same results

---

<div class="post-metadata">

**Author:** ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)\
**Post date:** [June 22, 2019, 6:25pm UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/5 "2019-06-22T18:25:39Z")

</div>

Did you label the bahamas\_leaks\_nodes and the intermediary as 'Node'?  
Intemediary nodes should have different label. In your MATCH the label is same for both MATCH statements.

Run this  
MATCH (n1:Node) WHERE n1.node\_id = "23000001" RETURN n1  
and see if you get any result.

---

<div class="post-metadata">

**Author:** ![wilsomrm2](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/wilsomrm2/32/5351_2.png) [@wilsomrm2](https://community.neo4j.com/u/wilsomrm2)\
**Post date:** [June 22, 2019, 6:57pm UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/6 "2019-06-22T18:57:44Z")

</div>

Yes I have tried multiple queries over the week  
I have named lables inline with the following Cypher.

neo4j\> LOAD CSV WITH HEADERS FROM "file:///intermediary\_of.csv" AS row  
WITH row WHERE row.rel\_type = "intermediary\_of"  
MATCH (n1:Intermediary) WHERE n1.node\_id = row.node\_1  
MATCH (n2:Entity) WHERE n2.node\_id = row.node\_2  
CREATE (n1)-[:INTERMEDIARY\_OF]-\>(n2);

....but still get the following error.

**Connection to the database terminated. This can happen due to network instabilities, or due to restarts of the database**

---

<div class="post-metadata">

**Author:** ![wilsomrm2](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/wilsomrm2/32/5351_2.png) [@wilsomrm2](https://community.neo4j.com/u/wilsomrm2)\
**Post date:** [June 22, 2019, 6:59pm UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/7 "2019-06-22T18:59:42Z")

</div>

The Cypher

MATCH (n1:Node) WHERE n1.node\_id = 23000001 RETURN n1

returns  
n1  
{  
"sourceID": "Bahamas Leaks",  
"name": "Internal User",  
"valid\_until": "The Bahamas Leaks data is current through early 2016.",  
"node\_id": 23000001  
}

---

<div class="post-metadata">

**Author:** ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)\
**Post date:** [June 22, 2019, 8:18pm UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/8 "2019-06-22T20:18:41Z")

</div>

If the node\_id is stored as integer then try this:

MATCH (n1:Node) WHERE n1.node\_id = toInteger(row.node\_1)  
MATCH (n2:Node) WHERE n2.node\_id = toInteger(row.node\_2)

---

<div class="post-metadata">

**Author:** ![wilsomrm2](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/wilsomrm2/32/5351_2.png) [@wilsomrm2](https://community.neo4j.com/u/wilsomrm2)\
**Post date:** [June 22, 2019, 8:43pm UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/9 "2019-06-22T20:43:12Z")

</div>

neo4j\> MATCH (n1:Intermediary) WHERE n1.node\_id = 23000001 RETURN n1;  
+-------------------------------------------------------------------------------------------------------------------------------------------------------------+  
| n1 |  
+-------------------------------------------------------------------------------------------------------------------------------------------------------------+  
| (:Intermediary {sourceID: "Bahamas Leaks", name: "Internal User", valid\_until: "The Bahamas Leaks data is current through early 2016.", node\_id: 23000001}) |  
+-------------------------------------------------------------------------------------------------------------------------------------------------------------+

1 row available after 103 ms, consumed after another 187 ms

neo4j\> MATCH (n2:Entity) WHERE n2.node\_id =20000035 RETURN n2;  
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+  
| n2 |  
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+  
| (:Entity {sourceID: "Bahamas Leaks", name: "TINU HOLDINGS LIMITED", valid\_until: "The Bahamas Leaks data is current through early 2016.", node\_id: 20000035}) |  
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+

1 row available after 98 ms, consumed after another 572 ms

neo4j\> LOAD CSV WITH HEADERS FROM "file:///intermediary\_of.csv" AS row  
WITH row WHERE row.rel\_type = "intermediary\_of"  
MATCH (n1:Intermediary) WHERE n1.node\_id = row.node\_1  
MATCH (n2:Entity) WHERE n2.node\_id = row.node\_2  
CREATE (n1)-[:INTERMEDIARY\_OF]-\>(n2);

**Connection to the database terminated. This can happen due to network instabilities, or due to restarts of the database**

Caused the DB to exit.

neo4j\> USING PERIODIC COMMIT 500  
LOAD CSV WITH HEADERS FROM "file:///intermediary\_of.csv" AS row  
WITH row WHERE row.rel\_type = "intermediary\_of"  
MATCH (n1:Intermediary) WHERE n1.node\_id = row.node\_1  
MATCH (n2:Entity) WHERE n2.node\_id = row.node\_2  
CREATE (n1)-[:INTERMEDIARY\_OF]-\>(n2);  
**0 rows available after 1207271 ms, consumed after another 2 ms**

Although this did not cause the DB to exit this time in the prompt it was dead.

neo4j\> USING PERIODIC COMMIT 500  
LOAD CSV WITH HEADERS FROM "file:///intermediary\_of.csv" AS row  
WITH row WHERE row.rel\_type = "intermediary\_of"  
MATCH (n1:Intermediary) WHERE n1.node\_id = toInteger(row.node\_1)  
MATCH (n2:Entity) WHERE n2.node\_id = toInteger(row.node\_2)  
CREATE (n1)-[:INTERMEDIARY\_OF]-\>(n2);  
**Connection to the database terminated. This can happen due to network instabilities, or due to restarts of the database**

VERY Frustrating!

---

<div class="post-metadata">

**Author:** ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)\
**Post date:** [June 22, 2019, 9:52pm UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/10 "2019-06-22T21:52:40Z")

</div>

Please share your LOAD CSV code that you used to create Entity and Intemediary nodes. I will use that in my DB and check.

---

<div class="post-metadata">

**Author:** ![wilsomrm2](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/wilsomrm2/32/5351_2.png) [@wilsomrm2](https://community.neo4j.com/u/wilsomrm2)\
**Post date:** [June 22, 2019, 11:59pm UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/11 "2019-06-22T23:59:13Z")

</div>

Hi I used neo4j-admin import to initially setup the DB with the nodes and a set of edges.

I am now trying to use load CVS to add some additional edges/relationships.

This is not straight forward, very unstable,

---

<div class="post-metadata">

**Author:** ![wilsomrm2](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/wilsomrm2/32/5351_2.png) [@wilsomrm2](https://community.neo4j.com/u/wilsomrm2)\
**Post date:** [June 23, 2019, 2:01am UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/12 "2019-06-23T02:01:55Z")

</div>

To load additional nodes I use

USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM '[http://IP/bahamas\_leaks.nodes.intermediary.csv](http://IP/bahamas_leaks.nodes.intermediary.csv)  
' AS line CREATE (:Intermediaries { name: line.name, internal\_id: line.internal\_id, address: line.address, valid\_until: line.valid\_until, country\_codes: line.country\_codes, countries: line.countries, status: line.status, node\_id: toInt(line.node\_id), sourceID: line.sourceID})

Its all importing right and can get data out correctly.....schema is in as understood.

Very strange.

I have the Enterprise Version on an AWS cluster.

---

<div class="post-metadata">

**Author:** ![wilsomrm2](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/wilsomrm2/32/5351_2.png) [@wilsomrm2](https://community.neo4j.com/u/wilsomrm2)\
**Post date:** [June 23, 2019, 5:10am UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/13 "2019-06-23T05:10:01Z")

</div>

OK looks like I have a partial import of the edge/relation now when I slow down the processing via the periodic commit

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/2X/d/d10a235f6ea36c2e3b344c5f7c20b3f2c30eee31.png)

Maybe a bad character in the cvs input stream

---

<div class="post-metadata">

**Author:** ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)\
**Post date:** [June 23, 2019, 6:34am UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/14 "2019-06-23T06:34:51Z")

</div>

Good to hear that. All is well that ends well!

---

<div class="post-metadata">

**Author:** ![wilsomrm2](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/wilsomrm2/32/5351_2.png) [@wilsomrm2](https://community.neo4j.com/u/wilsomrm2)\
**Post date:** [June 23, 2019, 11:54am UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/15 "2019-06-23T11:54:25Z")

</div>

INot quite solved yet. The output on the state of the import from Neo4j gives little clues on what the issue is. Looked at the input stream and cant find an issue. Very painful!

---

<div class="post-metadata">

**Author:** ![wilsomrm2](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/wilsomrm2/32/5351_2.png) [@wilsomrm2](https://community.neo4j.com/u/wilsomrm2)\
**Post date:** [June 23, 2019, 12:19pm UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/16 "2019-06-23T12:19:20Z")

</div>

Looked at the data and it is clean no special chars.

Stops exactly on 6500 entries.

Now I am wondering if I am hitting an Neo4j limitation.

---

<div class="post-metadata">

**Author:** ![wilsomrm2](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/wilsomrm2/32/5351_2.png) [@wilsomrm2](https://community.neo4j.com/u/wilsomrm2)\
**Post date:** [June 23, 2019, 5:32pm UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/17 "2019-06-23T17:32:46Z")

</div>

This looks to be a heap size issue limitation with Neo4j.

Will look to do the following.

Break up import sizes into multiple imports.

Increase Java and Neo4j heapsize.

Increase the periodic commit even further.

Looks like Neo4j tries to do everything in memory before committing...that will always be a limiting factor in any systems architecture esp when dealing with big data....they prob. should look at doing some of this via virtual memory

I will next work out how to use apoc.periodic.iterate to see if that helps

---

<div class="post-metadata">

**Author:** ![andrew\_bowman](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/andrew_bowman/32/73_2.png) [@andrew\_bowman](https://community.neo4j.com/u/andrew_bowman)\
**Post date:** [June 23, 2019, 9:34pm UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/18 "2019-06-23T21:34:47Z")

</div>

There's no mention of indexes or constraints here. If you were running into heap issues when using periodic commit CSV loading using MATCHes, more than likely you don't have indexes up on the label/property used for lookup, meaning for each row you're doing an entire label scan, which would explain the heap pressure.

Please use an [EXPLAIN](https://neo4j.com/docs/cypher-manual/current/query-tuning/how-do-i-profile-a-query/) on your load query, and if you see NodeByLabelScan it means you aren't using index lookups, and should create indexes (or unique constraints) to make your matches quick and ease up heap pressure.

---

<div class="post-metadata">

**Author:** ![wilsomrm2](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/wilsomrm2/32/5351_2.png) [@wilsomrm2](https://community.neo4j.com/u/wilsomrm2)\
**Post date:** [June 24, 2019, 5:11am UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/19 "2019-06-24T05:11:43Z")

</div>

Hi Andrew,

OK understood.

I did start to look at the indexing over the weekend as I also thought that maybe an issue.

I will get this in place and feedback as required.

Thank you for the feedback.

All the Best  
Mike

---

<div class="post-metadata">

**Author:** ![wilsomrm2](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/wilsomrm2/32/5351_2.png) [@wilsomrm2](https://community.neo4j.com/u/wilsomrm2)\
**Post date:** [June 24, 2019, 5:32am UTC](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256/20 "2019-06-24T05:32:34Z")

</div>

Hi Andrew,

Thank God!

It works and was fast!

Now I can move forward!

Thank you so much for that feedback.

All the Best  
Mike

[Next page](https://community.neo4j.com/t/inserting-a-relationship-post-database-setup/8256.md?page=2)
