0
votes

I am currently using neo4j 2.2.5. I have around 30 million real flights and around thousands airport. I have Flight and Airport nodes and also I have HAS_FLIGHT and FLYING_TO relationships. Those relationships are connected the two nodes, source Airport node has connected with Flight node by HAS_FLIGHT relationship and Flight nodes has connected by FLYING_TO relationship with destination Airport.

So my question is when I tried to find the path flight from London city to Tokyo city with maximum 2 layovers airports or transit airports, my query will take more than 20 minutes and finally the connection is lost.

Here is my query:

//Flights path from London to Tokyo

MATCH path = (london :Airport{city:'London'})-[:HAS_FLIGHT|FLYING_TO*0..6]->(tokyo :Airport{city:'Tokyo'}) RETURN path;

1
Do you have an index on :Airport(city)? In general, see this blog post for information on optimizing Cypher queries.William Lyon
william Yes I already created index.Dawit Haile

1 Answers

1
votes

The query above gives you all the paths up to a level of 6. In most cases you just want the shortest path(s):

MATCH path = allShortestPaths( (london :Airport{city:'London'})-[:HAS_FLIGHT|FLYING_TO*0..6]->(tokyo :Airport{city:'Tokyo'}))
RETURN path;

shortestPath and allShortestPaths are way much faster since they skip paths that will get longer as early as possible. This should put much less pressure on memory and garbage collection.

Also double check on indexes as William mentioned in his comment.