Dantepy
Dantepy

Reputation: 1

How to create relationship in neo4j fast

Today I have create 591,113 nodes in my neo4j. Then I want create relationships on them using following code:

MATCH (A), (B)
WHERE A.value = B.value
CREATE (A)-[:SameValue]->(B)

But this took me for hours(and I have to terminate it before it finish). And I want to ask how to create relationship on a big amount of nodes fast?

Upvotes: 0

Views: 632

Answers (2)

Brian Underwood
Brian Underwood

Reputation: 10856

Do you have indexes on the value properties?

This also might work better (still, indexes are important):

MATCH (a:A) WITH a
  MATCH (b:B {value: a.value})
  CREATE a-[:SameValue]-b

Upvotes: 3

JohnMark13
JohnMark13

Reputation: 3739

You could try:

MATCH (a:UseLabels)
WITH a
MATCH (b:UseLabels{value:a.value})
CREATE (a)-[:SameValue]->(b)

It only matches values that match and avoid the cartesian product.

Upvotes: 3

Related Questions