3

所以我尝试使用新的合并语法来减少我需要确保两个节点存在并将它们链接起来的操作量。这是基本思想:

merge (first:Label{key:'value'})
merge (second:Label{key:'value'})
create unique first-[:rel]->second
set first.prop="x"
set second.prop="y"

这将需要至少 3 次使用 1.9 系统税的 API 调用,以确保每个节点首先存在并在第三个请求中链接它们(并设置属性)。

看来我的批次(充满了这些请求)可以正常工作,但也会引发一些异常(有时是不可预测的)。这是我的日志所说的:

de.ibm.ica.tripletstore.TripletWriterCypher2.process(TripletWriterCypher2.java:161) - FATAL [15:48:58,954] [ {
  "method" : "POST",
  "to" : "/cypher",
  "body" : {
    "query" : "CYPHER 2.0 merge (x:`person`{`key`:'John Doe'}) merge (y:`occupation`{`key`:'Developer'})  create unique x-[r:`works as`]-y with x, y, r SET x.`annotation`='com.ibm.ica.tutorial.anno.en.Person' SET y.`annotation`='com.ibm.ica.tutorial.anno.en.Occupation'  return x.key, y.key, type(r)"
  },
  "id" : 0
}, {
  "method" : "POST",
  "to" : "/cypher",
  "body" : {
    "query" : "CYPHER 2.0 merge (x:`person`{`key`:'John Doe'}) merge (y:`organization`{`key`:'IBM'})  create unique x-[r:`works for`]-y with x, y, r SET x.`annotation`='com.ibm.ica.tutorial.anno.en.Person' SET y.`country`='United States ' SET y.`industry`='Software & Services ' SET y.`annotation`='com.ibm.ica.tutorial.anno.en.Company'  return x.key, y.key, type(r)"
  },
  "id" : 1
}, {
  "method" : "POST",
  "to" : "/cypher",
  "body" : {
    "query" : "CYPHER 2.0 merge (x:`person`{`key`:'Ginny Rometty'}) merge (y:`organization`{`key`:'IBM'})  create unique x-[r:`works for`]-y with x, y, r SET x.`annotation`='com.ibm.ica.tutorial.anno.en.Person' SET y.`country`='United States ' SET y.`industry`='Software & Services ' SET y.`annotation`='com.ibm.ica.tutorial.anno.en.Company'  return x.key, y.key, type(r)"
  },
  "id" : 2
}, {
  "method" : "POST",
  "to" : "/cypher",
  "body" : {
    "query" : "CYPHER 2.0 merge (x:`person`{`key`:'Ginny Rometty'}) merge (y:`occupation`{`key`:'CEO'})  create unique x-[r:`works as`]-y with x, y, r SET x.`annotation`='com.ibm.ica.tutorial.anno.en.Person' SET y.`annotation`='com.ibm.ica.tutorial.anno.en.Occupation'  return x.key, y.key, type(r)"
  },
  "id" : 3
}, {
  "method" : "POST",
  "to" : "/cypher",
  "body" : {
    "query" : "CYPHER 2.0 merge (x:`person`{`key`:'Simon Sample'}) merge (y:`occupation`{`key`:'CTP'})  create unique x-[r:`works as`]-y with x, y, r SET x.`annotation`='com.ibm.ica.tutorial.anno.en.Person' SET y.`annotation`='com.ibm.ica.tutorial.anno.en.Occupation'  return x.key, y.key, type(r)"
  },
  "id" : 4
}, {
  "method" : "POST",
  "to" : "/cypher",
  "body" : {
    "query" : "CYPHER 2.0 merge (x:`person`{`key`:'Simon Sample'}) merge (y:`organization`{`key`:'IBM'})  create unique x-[r:`works for`]-y with x, y, r SET x.`annotation`='com.ibm.ica.tutorial.anno.en.Person' SET y.`country`='United States ' SET y.`industry`='Software & Services ' SET y.`annotation`='com.ibm.ica.tutorial.anno.en.Company'  return x.key, y.key, type(r)"
  },
  "id" : 5
}, {
  "method" : "POST",
  "to" : "/cypher",
  "body" : {
    "query" : "CYPHER 2.0 merge (x:`person`{`key`:'John Doe'}) merge (y:`person`{`key`:'Sally Sample'})  create unique x-[r:`coworker of`]-y with x, y, r SET x.`annotation`='com.ibm.ica.tutorial.anno.en.Person' SET y.`annotation`='com.ibm.ica.tutorial.anno.en.Person'  return x.key, y.key, type(r)"
  },
  "id" : 6
}, {
  "method" : "POST",
  "to" : "/cypher",
  "body" : {
    "query" : "CYPHER 2.0 merge (x:`person`{`key`:'Sam Sampleman'}) merge (y:`person`{`key`:'John Doe'})  create unique x-[r:`coworker of`]-y with x, y, r SET x.`annotation`='com.ibm.ica.tutorial.anno.en.Person' SET y.`annotation`='com.ibm.ica.tutorial.anno.en.Person'  return x.key, y.key, type(r)"
  },
  "id" : 7
}, {
  "method" : "POST",
  "to" : "/cypher",
  "body" : {
    "query" : "CYPHER 2.0 merge (x:`person`{`key`:'Johnny English'}) merge (y:`person`{`key`:'Sam Sampleman'})  create unique x-[r:`coworker of`]-y with x, y, r SET x.`annotation`='com.ibm.ica.tutorial.anno.en.Person' SET y.`annotation`='com.ibm.ica.tutorial.anno.en.Person'  return x.key, y.key, type(r)"
  },
  "id" : 8
}, {
  "method" : "POST",
  "to" : "/cypher",
  "body" : {
    "query" : "CYPHER 2.0 merge (x:`person`{`key`:'Johnny English'}) merge (y:`occupation`{`key`:'CTP'})  create unique x-[r:`works as`]-y with x, y, r SET x.`annotation`='com.ibm.ica.tutorial.anno.en.Person' SET y.`annotation`='com.ibm.ica.tutorial.anno.en.Occupation'  return x.key, y.key, type(r)"
  },
  "id" : 9
}, {
  "method" : "POST",
  "to" : "/cypher",
  "body" : {
    "query" : "CYPHER 2.0 merge (x:`person`{`key`:'Larry Page'}) merge (y:`organization`{`key`:'Google'})  create unique x-[r:`works for`]-y with x, y, r SET x.`annotation`='com.ibm.ica.tutorial.anno.en.Person' SET y.`country`='United States ' SET y.`industry`='Software & Services ' SET y.`annotation`='com.ibm.ica.tutorial.anno.en.Company'  return x.key, y.key, type(r)"
  },
  "id" : 10
}, {
  "method" : "POST",
  "to" : "/cypher",
  "body" : {
    "query" : "CYPHER 2.0 merge (x:`person`{`key`:'Larry Page'}) merge (y:`occupation`{`key`:'CEO'})  create unique x-[r:`works as`]-y with x, y, r SET x.`annotation`='com.ibm.ica.tutorial.anno.en.Person' SET y.`annotation`='com.ibm.ica.tutorial.anno.en.Occupation'  return x.key, y.key, type(r)"
  },
  "id" : 11
}, {
  "method" : "POST",
  "to" : "/cypher",
  "body" : {
    "query" : "CYPHER 2.0 merge (x:`person`{`key`:'Mark Elliot Zuckerberg'}) merge (y:`organization`{`key`:'Facebook'})  create unique x-[r:`works for`]-y with x, y, r SET x.`annotation`='com.ibm.ica.tutorial.anno.en.Person' SET y.`country`=null SET y.`industry`=null SET y.`annotation`='com.ibm.ica.tutorial.anno.en.Company'  return x.key, y.key, type(r)"
  },
  "id" : 12
}, {
  "method" : "POST",
  "to" : "/cypher",
  "body" : {
    "query" : "CYPHER 2.0 merge (x:`person`{`key`:'Mark Elliot Zuckerberg'}) merge (y:`occupation`{`key`:'CEO'})  create unique x-[r:`works as`]-y with x, y, r SET x.`annotation`='com.ibm.ica.tutorial.anno.en.Person' SET y.`annotation`='com.ibm.ica.tutorial.anno.en.Occupation'  return x.key, y.key, type(r)"
  },
  "id" : 13
} ]
de.ibm.ica.tripletstore.TripletWriterCypher2.process(TripletWriterCypher2.java:168) - ERROR [15:48:58,961] java.lang.Exception: Bad response code. 
{
  "message" : "{\r\n  \"message\" : \"If you create multiple elements, you can only create one of each.\",\r\n  \"exception\" : \"ParameterWrongTypeException\",\r\n  \"fullname\" : \"org.neo4j.cypher.ParameterWrongTypeException\",\r\n  \"stacktrace\" : [ \"org.neo4j.cypher.internal.pipes.ExecuteUpdateCommandsPipe$$anonfun$org$neo4j$cypher$internal$pipes$ExecuteUpdateCommandsPipe$$exec$1.apply(ExecuteUpdateCommandsPipe.scala:59)\", \"org.neo4j.cypher.internal.pipes.ExecuteUpdateCommandsPipe$$anonfun$org$neo4j$cypher$internal$pipes$ExecuteUpdateCommandsPipe$$exec$1.apply(ExecuteUpdateCommandsPipe.scala:59)\", \"org.neo4j.cypher.internal.helpers.CollectionSupport$$anon$1.next(CollectionSupport.scala:47)\", \"scala.collection.Iterator$$anon$13.next(Iterator.scala:372)\", \"scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:371)\", \"scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:371)\", \"scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:371)\", \"scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:371)\", \"scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327)\", \"scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327)\", \"org.neo4j.cypher.internal.ClosingIterator$$anonfun$next$1.apply(ClosingIterator.scala:45)\", \"org.neo4j.cypher.internal.ClosingIterator.failIfThrows(ClosingIterator.scala:84)\", \"org.neo4j.cypher.internal.ClosingIterator.next(ClosingIterator.scala:43)\", \"scala.collection.Iterator$class.foreach(Iterator.scala:727)\", \"org.neo4j.cypher.internal.ClosingIterator.foreach(ClosingIterator.scala:31)\", \"scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48)\", \"scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:178)\", \"scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:45)\", \"scala.collection.TraversableOnce$class.to(TraversableOnce.scala:259)\", \"org.neo4j.cypher.internal.ClosingIterator.to(ClosingIterator.scala:31)\", \"scala.collection.TraversableOnce$class.toList(TraversableOnce.scala:243)\", \"org.neo4j.cypher.internal.ClosingIterator.toList(ClosingIterator.scala:31)\", \"org.neo4j.cypher.EagerPipeExecutionResult.<init>(EagerPipeExecutionResult.scala:32)\", \"org.neo4j.cypher.internal.executionplan.ExecutionPlanBuilder$$anonfun$5.apply(ExecutionPlanBuilder.scala:133)\", \"org.neo4j.cypher.internal.executionplan.ExecutionPlanBuilder$$anonfun$5.apply(ExecutionPlanBuilder.scala:131)\", \"org.neo4j.cypher.internal.executionplan.ExecutionPlanBuilder$$anon$1.execute(ExecutionPlanBuilder.scala:48)\", \"org.neo4j.cypher.ExecutionEngine$$anonfun$execute$1.apply(ExecutionEngine.scala:70)\", \"org.neo4j.cypher.ExecutionEngine$$anonfun$execute$1.apply(ExecutionEngine.scala:69)\", \"org.neo4j.cypher.ExecutionEngine.prepare(ExecutionEngine.scala:131)\", \"org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:69)\", \"org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:84)\", \"org.neo4j.cypher.javacompat.ExecutionEngine.execute(ExecutionEngine.java:79)\", \"org.neo4j.server.rest.web.CypherService.cypher(CypherService.java:94)\", \"java.lang.reflect.Method.invoke(Unknown Source)\", \"org.neo4j.server.web.Jetty6WebServer.invokeDirectly(Jetty6WebServer.java:294)\", \"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:71)\", \"java.lang.reflect.Method.invoke(Unknown Source)\" ]\r\n}",
  "exception" : "BatchOperationFailedException",
  "fullname" : "org.neo4j.server.rest.domain.BatchOperationFailedException",
  "stacktrace" : [ "org.neo4j.server.rest.batch.NonStreamingBatchOperations.invoke(NonStreamingBatchOperations.java:63)", "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:71)", "java.lang.reflect.Method.invoke(Unknown Source)" ]
}

我的猜测是,在短时间内触发多个合并会导致这个问题,每个都试图创建相同的节点或其他东西。是否应该根据每个元素的 id “按顺序”执行批处理?

4

0 回答 0