In my Neo4j application I have a products, products characteristics and list of votes(with double weight) for each product on a certain characteristic.
In order to sort a list of products by average weight of votes for a list of characteristics I need to perform a complex run-time Cypher query that will calculate a sum of avg weight for list of characteristics for each product.
This is my current Cypher query:
MATCH (parentP:Product)-[:CONTAINS]->(childP:Product)
WHERE id(parentP) = {productId}
WITH childP
OPTIONAL MATCH (p:Product)<-[:VOTED_FOR]-(v:Vote)-[:VOTED_ON]->(c:Characteristic)
WHERE id(p) = id(childP) AND id(c) IN {characteristicIds}
WITH childP, c, avg(v.weight) as weight
RETURN childP AS product, sum(weight) as weight
ORDER BY weight DESC
I know that Neo4j is extremely fast for graph traversal but no so good for aggregation (summing, counting, averaging, and so on). My system can have a large lists of votes for each characteristic on each product.
Please help me to denormilize this structure in order to avoid any performance issues with a big lists of votes.
PROFILE output for Brian's query:
Cypher version: CYPHER 2.2, planner: COST. 374933 total db hits in 1482 ms.
