O'Reilly logo

Neo4j Cookbook by Ankur Goel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Finding paths in Cypher along with their shortest route

The most common operation in any graph database is graph traversal, which includes finding all possible paths between the two nodes, the shortest path, and the shortest weighted path. In this recipe, we will cover them with the help of examples.

Getting ready

Let's create some sample data of airports and routes between them, using the following Cypher queries:

CREATE (ATL:Airport { city:'Atlanta' }),(ORD:Airport { city:'Chicago' }),(LAX:Airport { city:'Los Angeles' }),(DFW:Airport { city:'Dallas/Fort Worth' }),(AUS:Airport { city:'Austin' }) CREATE (ATL)-[:ROUTE { time:22 }]->(AUS),(AUS)-[:ROUTE { time:35 }]->(LAX),(ATL)-[:ROUTE { time:40 }]->(DFW),(DFW)-[:ROUTE { time:34 }]->(LAX),(ORD)-[:ROUTE ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required