Neo4j 密码查询

Neo4j 密码查询,neo4j,aggregate,cypher,Neo4j,Aggregate,Cypher,我有简单的用例,但仍然找不到解决方案。。。。 我有问题节点每个问题都有类别,每个类别可以有许多问题。 我想做以下工作: 检索5个问题,每个问题都来自不同的类别 START question=node:__types__(className = "com.socialist.server.graph.entities.Question") RETURN distinct(question.category), question LIMIT 5 尝试了以下内容,但这不是我想要的,因为我仍然

我有简单的用例,但仍然找不到解决方案。。。。
我有问题节点每个问题都有类别,每个类别可以有许多问题。 我想做以下工作:

检索5个问题,每个问题都来自不同的类别

 START question=node:__types__(className = "com.socialist.server.graph.entities.Question")
 RETURN distinct(question.category), question
 LIMIT 5
尝试了以下内容,但这不是我想要的,因为我仍然会收到来自同一类别的问题

 START question=node:__types__(className = "com.socialist.server.graph.entities.Question")
 RETURN distinct(question.category), question
 LIMIT 5
该用例的正确查询是什么?
您的答案很受欢迎。

类似的方法可能会奏效,但如果您的每个类别都有很多,那么这将不是最佳效率:

START question=node:__types__(className = "com.socialist.server.graph.entities.Question")
RETURN question.category, head(collect(question))
LIMIT 5
此外,很快(希望在2.0版本之前)就会有一种从集合中随机获取项目的好方法,如下所示:

START question=node:__types__(className = "com.socialist.server.graph.entities.Question")
WITH question.category as category, collect(question) as questions
RETURN category, questions[rand() * length(questions)]
LIMIT 5

你是如何对每个问题都有一个类别这一事实进行建模的?从您的查询来看,该类别似乎是问题的属性。为类别引入节点不是更有意义吗?嗨,谢谢你的评论。。。假设我有Category节点:问题-[:RELATE]->Category它将如何帮助实现我想要的?