Skip to content

Instantly share code, notes, and snippets.

@vranac vranac/relations
Last active Aug 29, 2015

Embed
What would you like to do?
Neo4j relationships
CREATE INDEX ON :Airport(IataCode);
CREATE INDEX ON :Deal(OriginId);
CREATE INDEX ON :Deal(DestinationId);
MATCH (ao:Airport),(d:Deal)
WHERE d.OriginId = ao.IataCode
MERGE (ao)-[ro:ORIGIN]->(d);
MATCH (ad:Airport),(d:Deal)
WHERE d.DestinationId = ad.IataCode
MERGE (d)-[rd:DESTINATION]->(ad);
@vranac

This comment has been minimized.

Copy link
Owner Author

commented Dec 6, 2014

OK, so I have two node labels, Airport and Deal.
Indexes created for them.
I need to create two type of relationships:

  • connecting origin airport to deal (lines 5-7)
  • connecting destination airport to deal (lines 9-11)

I triggered the creation of origin relationships on 5m deal nodes and 3.5k airports, 3.5hours later still working with some ~220k relationships created.

Can this be optimised, and is there something I am missing?

@jexp

This comment has been minimized.

Copy link

commented Dec 6, 2014

This should work better than the cross product:

MATCH (ao:Airport)
MATCH (d:Deal)
WHERE d.OriginId = ao.IataCode
MERGE (ao)-[ro:ORIGIN]->(d);

same here:

MATCH (ad:Airport)
MATCH (d:Deal)
WHERE d.DestinationId = ad.IataCode
MERGE (d)-[rd:DESTINATION]->(ad);
@jexp

This comment has been minimized.

Copy link

commented Dec 6, 2014

You should be able to profile both statements in neo4j-shell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.