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

查看:72
本文介绍了如何使用 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.

因此,您的代码将如下所示:

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

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

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