0
votes

With 500,000 nodes I'm getting 10-15 seconds, any idea how I can optimize this?

start n=node(*) WHERE HAS(n.score) RETURN n, n.score ORDER BY n.score DESC Limit 5;

from looking around I get the sense that the WHERE clause is slowing it down but I'm not sure how I can use a MATCH on a property of a node.

2

2 Answers

1
votes

As Luanne says it takes time because your are searching in all the nodes of your graph. You could search only in the nodes that has a score property (by indexing them, by searching them from a common node, or - if you're using Neo4j 2 - by labeling them)

See http://docs.neo4j.org/chunked/milestone/indexing.html for further explanations on indexes (which seems to be the more common solution).

0
votes

With node(*) you're effectively touching your entire graph of 500,000 nodes to check the presence of a property, and the ordering the results. How many rows do you get back? If you drop your order clause is it any faster?

And what's your use case? Wondering if you can model this differently to avoid a global graph operation. For example, index nodes with the score property, or create a relation from all nodes with the score property to some sort of reference node. Depends on your use case really