通过Rest API在一个密码查询中执行多个CREATE UNIQUE

b.m*_*yet 3 rest neo4j cypher

使用Neo4j版本1.8.1,我试图利用"cypher"REST入口点插入许多关系(查询必须插入关系,并且只在必要时才有目标节点).我通过http://christophewillemsen.com/streemz/8/importing-initial-data-with-the-neo4j-rest-api博文发现了这种可能性.

如果我只创建一个关系,它会很好用,但是当我尝试几个关系时它会失败.

JSON用于调用一个正常工作的关系:

{"query":"START n=node:node_auto_index(UserId='21000001') CREATE UNIQUE n-[:KNOWS{Label:'Friend'}]-(m{Users})", "params":{"Users" : [{"UserId":"21000003"}]}}
Run Code Online (Sandbox Code Playgroud)

我试图建立两个失败的关系:

{"query":"START n=node:node_auto_index(UserId='21000001') CREATE UNIQUE n-[:KNOWS{Label:'Friend'}]-(m{Users})", "params":{"Users" : [{"UserId":"21000002"},{"UserId":"21000003"}]}}
Run Code Online (Sandbox Code Playgroud)

REST调用重新发送的错误是:

{
    "message": "The pattern CreateUniqueAction(List(m-[:`LOVES`]-n)) produced multiple possible paths, and that is not allowed",
    "exception": "UniquePathNotUniqueException",
    "stacktrace": "..."
}
Run Code Online (Sandbox Code Playgroud)

我不知道在Neo4j中我的查询是如何转换的,我很难找到如何更改查询.

我认为Neo4j会做2个查询,但是由于错误,它似乎正在为其他节点端做一些IN语句.

我也尝试将params作为列表,但它没有用.

谢谢您的帮助

Mic*_*ger 5

请确保始终使用密码查询中的参数

使用rest-batch-operations执行多个查询,请参阅http://docs.neo4j.org/chunked/milestone/rest-api-batch-ops.html

   POST `http://localhost:7474/db/data/batch`
   Accept: application/json
   Content-Type: application/json
   [ {
     "method" : "POST",
     "to" : "/cypher",
     "body" : {
       "query" : "START n=node:node_auto_index(UserId={userId1}), m=node:node_auto_index(UserId={userId2}) CREATE UNIQUE n-[r:KNOWS{Label:{label}}]-m",
       "params" : {"userId1":"21000001", "userId2":"21000002","label":"Friend"}
     },
     "id" : 0
   },
   {
     "method" : "POST",
     "to" : "/cypher",
     "body" : {
       "query" : "START n=node:node_auto_index(UserId={userId1}), m=node:node_auto_index(UserId={userId2}) CREATE UNIQUE n-[r:KNOWS{Label:{label}}]-m",
       "params" : {"userId1":"21000003", "userId2":"21000005","label":"Friend"}
     },
     "id" : 1
   } ]
Run Code Online (Sandbox Code Playgroud)