Skip to content Skip to sidebar Skip to footer

How Do I Import Python Node Dicts Into Neo4j?

I produce the following node and relationship data in a for loop about 1 million times. The idea is that investor nodes connect to company nodes by relationship edges: investor = {

Solution 1:

In py2neo a Node is defined in following manner:

class Node(*labels, **properties)

Each node has a label and can have many properties. In this case, Investor node can de defined by setting the label investor and properties of the node to be name and CIK.

investor_node = Node('investor', name = owner['name'], CIK = owner['CIK'])

Similarly, company node would look like:

company_node = Node('company', name = json['issuerName'], SIC = json['issuerSIC'])

Relationship are defined in following manner :

class Relationship(start_node, type, end_node, **properties)

In this case Relationship can be defined using:

investor_company_relationship = Relationship(investor_node, "is_director", company_node)

You can find one sample implementation of neo4j graph here.

Solution 2:

You could use UNWIND clause. Something like

WITH {json} ASdocumentUNWINDdocumentAS company
MERGE (c:company {c_id:company.id})
 SET c.sic=company.issuerSIC

If some of your json items is list again, you can use UNWIND as much as you like: UNWIND document.list_of_some_property

Post a Comment for "How Do I Import Python Node Dicts Into Neo4j?"