RNeo4j错误:400错误请求

时间:2015-02-11 00:52:13

标签: neo4j cypher r-neo4j

我不知道为什么我会收到以下错误,但我认为这是我做错了。

首先,您可以通过从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

我可以成功加载数据框dat的前49条记录,但第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

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

1 个答案:

答案 0 :(得分:3)

这是MERGE如何运作的问题。通过在score子句中设置MERGE属性...

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

... MERGE尝试创建整个模式,因此违反了您的唯一性约束。相反,这样做:

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

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