1

我不确定为什么会出现以下错误,但我想这是我做错了。

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

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

4

1 回答 1

3

这是如何MERGE工作的问题。通过score在此处设置子句本身的属性MERGE...

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

...MERGE尝试创建整个模式,因此违反了您的唯一性约束。相反,请执行以下操作:

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

进行此更改后,我能够导入您的所有数据。

于 2015-02-11T01:21:46.500 回答