在针对neo4j的REST API中,如何合并或创建节点? [英] In REST API for neo4j, how to merge or create nodes?
问题描述
我正在Windows 10笔记本电脑上运行neo4j(社区"版)的本地实例.我的客户端使用Java,并使用REST API(通过端口7474)与neo4j数据库进行通讯.
I am running a local instance of neo4j ("Community" edition) on a Windows 10 laptop. My client is in Java and uses the REST API (via port 7474) to talk with the neo4j database.
问题:是否有某种方法可以通过对/db/data/node
端点的REST API调用来获得等价于cypher中的MERGE/CREATE
指令?
QUESTION: is there some way to get the equivalent of a MERGE/CREATE
directive in cypher to happen via the REST API call to /db/data/node
endpoint?
我猜想我可以对不同的节点类型施加唯一的约束,并实现所需的行为.但是开箱即用,我希望的是单个端点,例如/db/data/node
,它可以创建入站数据或将入站数据与图中的任何现有节点合并.
I'm guessing that I could impose a unique constraint on different node types and achieve the desired behavior. But out of the box, what I am hoping for is a single endpoint -- Eg, /db/data/node
-- which either creates or merges the inbound data with any existing nodes in the graph.
推荐答案
您不必弄清楚如何获得等价"的Cypher子句,例如MERGE/CREATE
.您可以通过以下任一REST端点直接使用Cypher:
You don't have to figure out how to get the "equivalent" of Cypher clauses like MERGE/CREATE
. You can use Cypher directly via either of these REST endpoints:
- /db/data/transaction
- /db/data/cypher
但是,如果只想使用/db/data/node
端点,则可以利用
However, if you only want to use the /db/data/node
endpoint, you can take advantage of unique indexing and use either the uniqueness=get_or_create
or uniqueness=create_or_fail
URL parameters.
这篇关于在针对neo4j的REST API中,如何合并或创建节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!