Reputation: 10740
I'm trying to get all the relationships connected to a given node that also have a property called 'name'. this is my cypher:
MATCH (starting { number:'123' })<-[r]-() WHERE HAS(r.name) RETURN r
this is unimaginably slow! it takes neo4j ages to compute even if there are only few return values, and there are not so many relationships connected to the node (1 to 10 relationships at most).
am I doing something wrong here? other cyphers works fine.
thanks!
Upvotes: 2
Views: 61
Reputation: 3739
The number of relationships on the one node might be less relevant if you have not told Neo enough about your graph structure.
Firstly use labels and secondly use indexes. The below will Use a Label YourLabel
on the property number
.
CREATE INDEX ON :YourLabel(number)
Then hit the index to start the query, and use a type on your relationship too.
MATCH (:YourLabel{number:'123'})<-[r:RELATIONSHIP_TYPE]-()
WHERE HAS (r.name)
RETURN r
Now instead of scanning through every node for the number property with a value of 123, it reads only a single Index.
To use the labels, create your nodes like this (will be added to index):
CREATE (s1:YourLabel{number:"1"})
Upvotes: 3