2015-02-11 374 views
1

我不知道为什么我得到下面的错误,但我想这是我做错了。RNeo4j错误:400错误的请求

首先,您可以通过从this link下载文件dataset.r并将其加载到dget("dataset.r")的会话中来获取我的数据集。我会做dat = dget("dataset.r")

下面的代码是我用来将数据加载到Neo4j中的。

library(RNeo4j) 

graph = startGraph("http://localhost:7474/db/data/") 
graph$version 

# sure that the graph is clean -- you should backup first!!! 
clear(graph, input = FALSE) 

## ensure the constraints 
addConstraint(graph, "School", "unitid") 
addConstraint(graph, "Topic", "topic_id") 

## create the query 
## BE CAREFUL OF WHITESPACE between KEY:VALUE pairs for parameters!!! 
query = " 
MERGE (s:School {unitid:{unitid}, 
instnm:{instnm}, 
obereg:{obereg}, 
carnegie:{carnegie}, 
applefeeu:{applfeeu}, 
enrlft:{enrlft}, 
applcn:{applcn}, 
admssn:{admssn}, 
admit_rate:{admit_rate}, 
ape:{ape}, 
sat25:{sat25}, 
sat75:{sat75} }) 

MERGE (t:Topic {topic_id:{topic_id}, 
topic:{topic} }) 

MERGE (s)-[:HAS_TOPIC {score:{score} }]->(t) 
" 

for (i in 1:nrow(dat)) { 
    ## status 
    cat("starting row ", i, "\n") 
    ## run the query 
    cypher(graph, 
     query, 
     unitid = dat$unitid[i], 
     instnm = dat$instnm[i], 
     obereg = dat$obereg[i], 
     carnegie = dat$carnegie[i], 
     applfeeu = dat$applfeeu[i], 
     enrlft = dat$enrlt[i], 
     applcn = dat$applcn[i], 
     admssn = dat$admssn[i], 
     admit_rate = dat$admit_rate[i], 
     ape = dat$apps_per_enroll[i], 
     sat25 = dat$sat25[i], 
     sat75 = dat$sat75[i], 
     topic_id = dat$topic_id[i], 
     topic = dat$topic[i], 
     score = dat$score[i]) 
} #endfor 

我可以成功加载第49条记录我的数据框dat的,但错误出在第50排。

这是我收到的错误:

starting row 50 
Show Traceback 

Rerun with Debug 
Error: 400 Bad Request 

{"message":"Node 1477 already exists with label School and property \"unitid\"=[110680]","exception":"CypherExecutionException","fullname":"org.neo4j.cypher.CypherExecutionException","stacktrace":["org.neo4j.cypher.internal.compiler.v2_1.spi.ExceptionTranslatingQueryContext.org$neo4j$cypher$internal$compiler$v2_1$spi$ExceptionTranslatingQueryContext$$translateException(ExceptionTranslatingQueryContext.scala:154)","org.neo4j.cypher.internal.compiler.v2_1.spi.ExceptionTranslatingQueryContext$ExceptionTranslatingOperations.setProperty(ExceptionTranslatingQueryContext.scala:121)","org.neo4j.cypher.internal.compiler.v2_1.spi.UpdateCountingQueryContext$CountingOps.setProperty(UpdateCountingQueryContext.scala:130)","org.neo4j.cypher.internal.compiler.v2_1.mutation.PropertySetAction.exec(PropertySetAction.scala:51)","org.neo4j.cypher.internal.compiler.v2_1.mutation.MergeNodeAction$$anonfun$exec$1.apply(MergeNodeAction.scala:80)","org.neo4j.cypher.internal.compiler.v2_1 

这里是我的会话信息:

> sessionInfo() 
R version 3.1.0 (2014-04-10) 
Platform: x86_64-apple-darwin13.1.0 (64-bit) 

locale: 
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 

attached base packages: 
[1] stats  graphics grDevices utils  datasets methods base  

other attached packages: 
[1] RNeo4j_1.2.0 

loaded via a namespace (and not attached): 
[1] RCurl_1.95-4.1 RJSONIO_1.2-0.2 tools_3.1.0 

而且值得注意的是,我使用的Neo4j 2.1.3

感谢您提前提供任何帮助。

+0

__UPDATE__:我用'next'投掷'tryCatch'来跳过传递错误。以下是有问题的行:'50-55,364,661'。任何关于那些引起你注意的行 – Btibert3 2015-02-11 01:16:16

回答

3

这是MERGE工作方式的问题。通过设置MERGE条款本身这里内score财产...

MERGE (s)-[:HAS_TOPIC {score:{score} }]->(t) 

... MERGE试图创建整个模式,因此你的独特性约束被违反。相反,请执行以下操作:

MERGE (s)-[r:HAS_TOPIC]->(t) 
SET r.score = {score} 

在进行此更改后,我可以导入所有数据。