Optimizing Hierarchical Transit Time Queries in Neo4j

Hello Neo4j Community,

I’m working on a transportation network model in Neo4j where I need to calculate transit times across various geographic levels, such as province-to-province, province-to-FSA, and so on. My graph includes nodes for postal codes, FSAs, cities, and provinces, with relationships representing direct transit links between these entities.

I’ve structured my data with hierarchical relationships and have written separate Cypher queries for each specific transit time condition. However, I’m concerned about the efficiency and potential repetition of these queries. I’m looking for advice on how to optimize my model and queries to handle different levels of transit time combinations more effectively.

Here’s an example of the type of query I’m using:

MATCH (src:PostalCode {code: 'SRC_POSTALCODE'})-[r:CONNECTS_TO]->(des:Province {name: 'DES_PROVINCE'})
RETURN r.transitTime AS DirectTransitTime

This query retrieves the direct transit time from a source postal code to a destination province. I have similar queries for other combinations, like FSA-to-city and city-to-province.

My questions are:

  1. How can I structure my graph to reduce the number of separate queries required for each condition?
  2. Is there a way to write a single, more efficient query that can handle all possible combinations of transit times?
  3. Are there best practices for modeling such hierarchical and interconnected data in Neo4j to improve query performance?

Any insights or suggestions on how to approach this problem would be greatly appreciated!

Thank you in advance for your help!