Hello everyone, i'm still new to neo4j and i'm trying to populate a neo4j database from a Java application using Neo4j Java Dirver and i just stumbled upon the necessity of combining two queries that so far i ran separately into a single one. Those queries are the following:
params.put( "nodes", nodes );
String query =
"UNWIND $nodes AS n " +
"MERGE (x:" + index + " {id: n.id}) " +
"ON CREATE SET x += n " +
"WITH x, n " +
"CALL apoc.create.addLabels([ id(x) ], [ n.category ]) yield node " +
"RETURN node";
session.run( query, params );
and
params.put( "relationships", relationships );
String query =
"UNWIND $relationships AS relationship " +
"MATCH (x:" + index + " {id: relationship.source_id}), (y:" + index + " {id: relationship.target_id}) " +
"MERGE (x)-[r:" + type + "]-(y)" +
"ON CREATE SET r += relationship";
session.run( query, params );
The first one creates nodes (if they already dont exist in the db) and adds a second label dinamically, the second one creates relationships by matching the nodes involved and creating a link if it doesnt exist. I would like to have those queries into a single method and possibly into the same query as follows:
params.put( "nodes", nodes );
params.put( "relationships", relationships );
String query =
"???";
session.run( query, params );
How can i make them into a single query?
Thanks in advance