python neo4j_如何使用Python将大量数据插入Neo4j

I want to insert some data into Neo4j using py2neo . Link to data file.

I am new to Neo4j. Can someone tell me how to insert bulk data into Neo4j.Actually i want to do performance testing of Neo4j.....

I have tried this but this is just for small data set ...

from pprint import pprint

from py2neo import neo4j,node, rel

graph_db = neo4j.GraphDatabaseService()

def insert_data():

die_hard = graph_db.create(

node(name="Bruce Willis"),

node(name="John McClane"),

node(name="Alan Rickman"),

node(name="Hans Gruber"),

node(name="Nakatomi Plaza"),

rel(0, "PLAYS", 1),

rel(2, "PLAYS", 3),

rel(1, "VISITS", 4),

rel(3, "STEALS_FROM", 4),

rel(1, "KILLS", 3),)

pprint(die_hard)

insert_data()

error :

src/test/java/org/neo4j/batchimport/TestDataGenerator.java:3: error: package org.junit does not exist

import org.junit.Ignore;

^

src/test/java/org/neo4j/batchimport/TestDataGenerator.java:14: error: cannot find symbol

@Ignore

^

symbol: class Ignore

2 errors

解决方案

Not sure if this is the issue you're having, but when I tried your sample, I got errors on the [name=] syntax. What's being passed to the node() constructor is a dictionary. There are multiple syntax for the node() constructor, and I didn't see a syntax that matches the one your using. So, try using dictionary syntax like this:

node({"name": "Bruce Willis"})

Also, I'm not sure if you've configured a default neo4j url, but I had to specify a connection point url in my new4j.GraphDatabaseService() call.

So, your code would look like:

from pprint import pprint

from py2neo import neo4j, node, rel

graph_db = neo4j.GraphDatabaseService('http://localhost:7474/db/data')

def insert_data():

die_hard = graph_db.create(

node({"name": "Bruce Willis"}),

node({"name": "John McClane"}),

node({"name": "Alan Rickman"}),

node({"name": "Hans Gruber"}),

node({"name": "Nakatomi Plaza"}),

rel(0, "PLAYS", 1),

rel(2, "PLAYS", 3),

rel(1, "VISITS", 4),

rel(3, "STEALS_FROM", 4),

rel(1, "KILLS", 3),)

pprint(die_hard)

insert_data()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值