2015-02-11 161 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} 

在進行此更改後,我可以導入所有數據。