pythonneo4jpy2neoneomodel

neo4j is taking too much time for the cypher query "MATCH (n:City{name : "hyderabad"})-[:CONTAINS]->(p:BusinessDetails) return p"


i am using neo4j community version , i am having 1 node of "City" , and approx 5000 nodes of "BusinessDetails" connected with realtion "CONTAINS" from "City" to "BusinessDetails" , when 1 am using the cypher query

MATCH (n:City{name : "hyderabad"})-[:CONTAINS]->(p:BusinessDetails) return p

it is taking approx 8 seconds to fetch the results. How to optimize this ? and why it is taking so much of time? i am really new with neo4j.


Solution

  • First of all make sure you've added index on the City name

    CREATE INDEX ON :City(name)
    

    Next always Match the filtering in a separate match statement

    MATCH (n:City{name : "hyderabad"})
    MATCH n-[:CONTAINS]->(p:BusinessDetails)
    RETURN p
    

    This will enhance your performance a bit. Anyway this can be a configuration problem or hardware as you are talking about very small numbers compared to what I'm using and still I'm having better performance.