3

そこで、新しいマージ構文を使用して、2 つのノードが存在することを確認し、それらをリンクするために必要な操作の量を削減しようとしました。基本的な考え方は次のとおりです。

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

1.9 systax で API を少なくとも 3 回呼び出して、各ノードが最初に存在することを確認し、3 番目の要求でそれらをリンク (およびプロパティを設定) する必要があります。

私のバッチ (これらの要求でいっぱい) は適切に機能しているように見えますが、いくつかの例外 (予測できない場合もあります) もスローします。これが私のログの内容です:

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