cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Most efficient way to create a large number of relationships with UNWIND & call apoc.when?

cnhx27
Node Link

Hi!,

I'm new to Neo4J Cypher.
I need to write a query, where will be create relationships between nodes by these rules:
Each node has a referenced_urls property described like this:

"[
	{"href":"http://f4b1.com/index.html","follow":true},
	{"href":"http://f4b1.com","follow":true},
	{"href":"http://f4b1.com/outils","follow":false},
	{"href":"http://f4b1.com/contact/create","follow":false},
        .........
]"

For each source node found & each referenced_urls value of this node, if the target node exists then create the relationships.

I wrote this Cypher request :

MATCH path = (n:F4b1_com)
UNWIND NODES(path) AS source
  UNWIND apoc.convert.fromJsonList(source.referenced_urls) AS referenced_urls
    CALL apoc.when(referenced_urls.follow = true, 
    "MATCH (target:F4b1_com {url: href}) RETURN target",
    '',
    {href:referenced_urls.href}) YIELD value
    WITH source, value.target AS target
      CREATE(source)-[r:LINK_TO]->(target)
  WITH source REMOVE source.referenced_urls

I can have about 50 000 nodes and 1000 referenced_urls value per node.
I'm not sure that's the efficient way

What would you advise me as optimizations?

0 REPLIES 0