我使用py2neo将数据转储到Neo4j数据库中。
有了这个
batch = neo4j.WriteBatch(graph_db)
batch.create(node(name="Alice"))
batch.create(node(name="Bob"))
batch.create(rel(0, "KNOWS", 1))
results = batch.submit()
我可以使用同一批次中的新节点创建关系。
但是,如果我尝试与批处理之前已创建的节点建立关系,如下所示:
n = graph_db.create({"name": "Smith"})
batch = neo4j.WriteBatch(graph_db)
batch.create(node(name="Alice"))
batch.create(rel(0, "KNOWS", n))
results = batch.submit()
失败*。 如何继续创建具有批量关系的节点到先前创建的节点?
使用py2neo 1.5.1和Neo4j 1.9.2
由于
SystemError:{u'stacktrace':[u'org.neo4j.server.rest.batch.NonStreamingBatchOperations.invoke(NonStreamingBatchOperations.java:63)',u'org.neo4j.server.rest.batch.BatchOperations。 performRequest(BatchOperations.java:188)',u'org.neo4j.server.rest.batch.BatchOperations.parseAndPerform(BatchOperations.java:159)',u'org.neo4j.server.rest.batch.NonStreamingBatchOperations.performBatchJobs( NonStreamingBatchOperations.java:48)',u'org.neo4j.server.rest.web.BatchOperationService.batchProcess(BatchOperationService.java:117)',u'org.neo4j.server.rest.web.BatchOperationService.performBatchOperations(BatchOperationService。 java:72)',u'java.lang.reflect.Method.invoke(Method.java:606)',u'org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)'] ,u'message':你'{\ n“消息”:“输入字符串:\”5078 \')]} \“”,\ n“异常”:“BadInputException”,\ n“全名”:“org .neo4j.server.rest.repr.BadInputException“,\ n”stacktrace“:[”org.neo4j.server.rest.web.RestfulGraphDa tabase.extractNodeId(RestfulGraphDatabase.java:171)“,”org.neo4j.server.rest.web.RestfulGraphDatabase.createRelationship(RestfulGraphDatabase.java:410)“,”java.lang.reflect.Method.invoke(Method.java: 606)“,”org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)“,”org.neo4j.server.web.Jetty6WebServer.invokeDirectly(Jetty6WebServer.java:302)“,”org .neo4j.server.rest.batch.NonStreamingBatchOperations.invoke(NonStreamingBatchOperations.java:55)“,”org.neo4j.server.rest.batch.BatchOperations.performRequest(BatchOperations.java:188)“,”org.neo4j.server .rest.batch.BatchOperations.parseAndPerform(BatchOperations.java:159)“,”org.neo4j.server.rest.batch.NonStreamingBatchOperations.performBatchJobs(NonStreamingBatchOperations.java:48)“,”org.neo4j.server.rest.web .BatchOperationService.batchProcess(BatchOperationService.java:117)“,”org.neo4j.server.rest.web.BatchOperationService.performBatchOperations(BatchOperationService.java:72)“,”java.lang.reflect.Method.invoke(Met hod.java:606)“,”org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)“],\ n”原因“:{\ n”message“:”对于输入字符串: \“5078 \')]} \”“,\ n”异常“:”NumberFormatException“,\ n”stacktrace“:[”java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)“,”java.lang .Long.parseLong(Long.java:441)“,”java.lang.Long.parseLong(Long.java:483)“,”org.neo4j.server.rest.web.RestfulGraphDatabase.extractNodeId(RestfulGraphDatabase.java:167 )“,”org.neo4j.server.rest.web.RestfulGraphDatabase.createRelationship(RestfulGraphDatabase.java:410)“,”java.lang.reflect.Method.invoke(Method.java:606)“,”org.neo4j“。 server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)“,”org.neo4j.server.web.Jetty6WebServer.invokeDirectly(Jetty6WebServer.java:302)“,”org.neo4j.server.rest.batch。 NonStreamingBatchOperations.invoke(NonStreamingBatchOperations.java:55)“,”org.neo4j.server.rest.batch.BatchOperations.performRequest(BatchOperations.java:188) “,”org.neo4j.server.rest.batch.BatchOperations.parseAndPerform(BatchOperations.java:159)“,”org.neo4j.server.rest.batch.NonStreamingBatchOperations.performBatchJobs(NonStreamingBatchOperations.java:48)“,”org .neo4j.server.rest.web.BatchOperationService.batchProcess(BatchOperationService.java:117)“,”org.neo4j.server.rest.web.BatchOperationService.performBatchOperations(BatchOperationService.java:72)“,”java.lang.reflect .Method.invoke(Method.java:606)“,”org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)“],\ n”fullname“:”java.lang.NumberFormatException“ \ n} \ n}',u'fullname':u'org.neo4j.server.rest.domain.BatchOperationFailedException',u'exception':u'BatchOperationFailedException'}
答案 0 :(得分:0)
在您的代码示例中,n
实际上将包含节点列表,而不是单个节点(请参阅create方法上的警告)。所以,而不是......
n = graph_db.create({"name": "Smith"})
......你可能想......
n, = graph_db.create({"name": "Smith"})