Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-19-2020 04:52 AM
I am trying to model a hyperedge in a graph, where a CHUNK
node has relations to TOKEN
nodes.
First I need to create if not exists, the tokens.
Then I need to check if the CHUNK
with relations to these two nodes exists.
If not exists, then I need to create a CHUNK node and also create the relations.
This is the Query that I have come up with:
MERGE
(t:TOKEN {text: "test token"})
MERGE
(p: PERSON {text:"test person"})
with t,p
OPTIONAL MATCH
(c:CHUNK)
WHERE
(c)-[:CONTAINS_TOKEN]->(t)
AND
(c)-[:CONTAINS_TOKEN]->(p)
FOREACH (ignoreme in case when c is NULL then [1] ELSE [] END|
CREATE (c: CHUNK)
CREATE (c)-[:CONTAINS_TOKEN]->(p)
CREATE (c)-[:CONTAINS_TOKEN]->(t)
)
My question is, is this the best way to try and merge
a node and multiple relations at the same time?
are there any APOC procedures that make this easier? I ask this because maybe at one point I need to create a hyper edge with more than two tokens, and then the query becomes quite large
07-19-2020 05:36 PM
Hi, you can use UNWIND. Neo4j supports many transactions.
Thanks
All the sessions of the conference are now available online