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

编程入门 行业动态 更新时间:2024-10-25 22:24:58
本文介绍了通过Rest API在一个密码查询中执行多个CREATE UNIQUE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用Neo4j版本1.8.1,我试图利用密码" REST入口点来插入许多关系(查询必须插入该关系,并且仅在必要时插入目标节点).我通过 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 christophewillemsen/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执行多个查询,请参见 docs.neo4j/chunked/milestone/rest-api-batch-ops.html

Use the rest-batch-operations to execute multiple queries, see docs.neo4j/chunked/milestone/rest-api-batch-ops.html

POST `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

本文发布于:2023-10-29 13:02:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539766.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   密码   API   Rest   CREATE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!