Random 如何使用Cypher返回Neo4j中的随机记录?
我有这样的疑问:Random 如何使用Cypher返回Neo4j中的随机记录?,random,neo4j,cypher,Random,Neo4j,Cypher,我有这样的疑问: $query = "MATCH (U:User) RETURN U ORDER BY RAND() LIMIT 100"; 但当我运行这个时,会显示错误。它说: 捕获的异常:无法执行查询[400]:标头:数组( [内容类型]=>application/json;字符集=UTF-8;流=true [访问控制允许来源]=>*[传输编码]=>分块 [服务器]=>Jetty(9.0.z-SNAPSHOT))主体:数组([消息
$query = "MATCH (U:User)
RETURN U
ORDER BY RAND()
LIMIT 100";
但当我运行这个时,会显示错误。它说:
捕获的异常:无法执行查询[400]:标头:数组(
[内容类型]=>application/json;字符集=UTF-8;流=true
[访问控制允许来源]=>*[传输编码]=>分块
[服务器]=>Jetty(9.0.z-SNAPSHOT))主体:数组([消息]=>顺序
BY表达式必须是确定性的。例如,不能使用
表达式[exception]=>PatternException中的rand()函数
[fullname]=>org.neo4j.cypher.PatternException[stacktrace]=>Array
( [0] =>
org.neo4j.cypher.internal.compiler.v2_0.commands.SortItem.apply(SortItem.scala:30)
[1] =>
org.neo4j.cypher.internal.compiler.v2_0.pipes.ExecutionContextComparer$class.compareBy(SortPipe.scala:43)
[2] =>
org.neo4j.cypher.internal.compiler.v2_0.pipes.TopPipe.compareBy(TopPipe.scala:33)
[3] =>
org.neo4j.cypher.internal.compiler.v2_0.pipes.toppie$$anonfun$1$$anonfun$apply$1.apply(toppie.scala:38)
[4] =>
org.neo4j.cypher.internal.compiler.v2_0.pipes.toppie$$anonfun$1$$anonfun$apply$1.apply(toppie.scala:38)
[5] =>scala.Option.forall(Option.scala:226)[6]=>
org.neo4j.cypher.internal.compiler.v2_0.pipes.TopPipe$$anonfun$1.apply(TopPipe.scala:38)
[7] =>
org.neo4j.cypher.internal.compiler.v2_0.pipes.TopPipe$$anonfun$1.apply(TopPipe.scala:38)
[8] =>
org.neo4j.cypher.internal.compiler.v2_0.pipes.TopPipe$$anonfun$internalCreateResults$1.apply(TopPipe.scala:56)
[9] =>
org.neo4j.cypher.internal.compiler.v2_0.pipes.TopPipe$$anonfun$internalCreateResults$1.apply(TopPipe.scala:49)
[10] =>scala.collection.Iterator$class.foreach(Iterator.scala:727)
[11] =>
org.neo4j.cypher.internal.compiler.v2_0.pipes.HeadAndTail.foreach(SlicePipe.scala:72)
[12] =>
org.neo4j.cypher.internal.compiler.v2_0.pipes.toppie.internalCreateResults(toppie.scala:49)
[13] =>
org.neo4j.cypher.internal.compiler.v2_0.pipes.PipeWithSource.createResults(Pipe.scala:71)
[14] =>
org.neo4j.cypher.internal.compiler.v2_0.pipes.PipeWithSource.createResults(Pipe.scala:68)
[15] =>
org.neo4j.cypher.internal.compiler.v2_0.executionplan.ExecutionPlanBuilder.org$neo4j$cypher$internal$compiler$v2_0$executionplan$ExecutionPlanBuilder$$prepareStateAndResult(ExecutionPlanBuilder.scala:149)
[16] =>
org.neo4j.cypher.internal.compiler.v2_0.executionplan.ExecutionPlanBuilder$$anonfun$2.apply(ExecutionPlanBuilder.scala:126)
[17] =>
org.neo4j.cypher.internal.compiler.v2_0.executionplan.ExecutionPlanBuilder$$anonfun$2.apply(ExecutionPlanBuilder.scala:125)
[18] =>
org.neo4j.cypher.internal.compiler.v2_0.executionplan.ExecutionPlanBuilder$$anon$6.execute(ExecutionPlanBuilder.scala:50)
[19] =>
org.neo4j.cypher.internal.ExecutionPlanWrapperForV2_0.execute(CypherCompiler.scala:93)
[20] =>
org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:61)
[21] =>
org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:65)
[22] =>
org.neo4j.cypher.javacompat.ExecutionEngine.execute(ExecutionEngine.java:78)
[23] =>
org.neo4j.server.rest.web.CypherService.cypher(CypherService.java:100)
[24]=>java.lang.reflect.Method.invoke(未知源)[25]=>
org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)
[26] =>
org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)
[27]=>java.lang.Thread.run(未知源)))
请帮帮我。谢谢。您需要按节点属性而不是函数进行订购。您可以执行以下操作(如果节点包含例如属性“name”):
在大数据集中可能会非常慢。您的编辑使代码与文章不匹配,使整个答案有点荒谬-1.
MATCH (u:User)
WITH u, rand() AS number
RETURN u
ORDER BY number
LIMIT 100