通过Rest API在一个密码查询中执行多个CREATE UNIQUE [英] Execute multiple CREATE UNIQUE in one cypher query through Rest API

查看:78
本文介绍了通过Rest API在一个密码查询中执行多个CREATE UNIQUE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Using Neo4j version 1.8.1, I'm trying to make use of the "cypher" REST entry point to insert many relationship (the query must insert the relationship, and only if necessary the destination node). I found this possibility through http://christophewillemsen.com/streemz/8/importing-initial-data-with-the-neo4j-rest-api blog post.

如果我仅创建一种关系,则效果很好,但是一旦尝试几种关系,它就会失败.

It works well if I create only one relationship but it fails as soon as I try several.

用于调用一种有效关系的JSON:

The JSON used to make the call for one relationship which is working :

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

我尝试建立2个失败的关系:

The one I tried to make 2 relationship which is failing :

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

REST调用重现的错误是:

The error Retunred by the REST call is :

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

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

Not knowing how exactly my query is transformed inside Neo4j it's hard to find how I must change my query.

我认为Neo4j会执行2个查询,但是由于出现错误,似乎它正在为另一节点执行IN语句.

I thought that Neo4j would do 2 queries, but by the errors it seems that it is doing kind of IN statement for the other node end.

我也尝试将参数作为列表,但是没有用.

I also tried to make params as a list but it did not worked.

谢谢您的帮助

推荐答案

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

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

Use the rest-batch-operations to execute multiple queries, see 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
   } ]

这篇关于通过Rest API在一个密码查询中执行多个CREATE UNIQUE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆