如何使用Python将大量数据插入Neo4j [英] How to insert Bulk data into Neo4j using Python

查看:1407
本文介绍了如何使用Python将大量数据插入Neo4j的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用py2neo将一些数据插入到Neo4j中. 链接到数据文件. 我是Neo4j的新手.有人可以告诉我如何向Neo4j中插入批量数据.实际上我想对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()

错误:

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

推荐答案

不确定这是否是您遇到的问题,但是当我尝试示例时,[name =]语法出现错误.传递给node()构造函数的是一本字典. node()构造函数有多种语法,但我没有看到与您使用的语法相匹配的语法.因此,尝试使用像这样的字典语法:

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"})

此外,我不确定您是否配置了默认的neo4j URL,但是我必须在new4j.GraphDatabaseService()调用中指定一个连接点URL.

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.

因此,您的代码如下:

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()

这篇关于如何使用Python将大量数据插入Neo4j的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆