gpt4 book ai didi

random - 如何使用 Cypher 在 Neo4j 中返回随机记录?

转载 作者:行者123 更新时间:2023-12-04 10:38:48 27 4
gpt4 key购买 nike

我有这样的查询:

$query = "MATCH (U:User)
RETURN U
ORDER BY RAND()
LIMIT 100";

但是当我运行它时,这会显示错误。它说:

Caught Exception: Unable to execute query [400]: Headers: Array ( [Content-Type] => application/json; charset=UTF-8; stream=true [Access-Control-Allow-Origin] => * [Transfer-Encoding] => chunked [Server] => Jetty(9.0.z-SNAPSHOT) ) Body: Array ( [message] => ORDER BY expressions must be deterministic. For instance, you cannot use the rand() function in the expression [exception] => PatternException [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.TopPipe$$anonfun$1$$anonfun$apply$1.apply(TopPipe.scala:38) [4] => org.neo4j.cypher.internal.compiler.v2_0.pipes.TopPipe$$anonfun$1$$anonfun$apply$1.apply(TopPipe.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.TopPipe.internalCreateResults(TopPipe.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(Unknown Source) [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(Unknown Source) ) )



请帮我。谢谢。

最佳答案

您需要按节点属性而不是函数进行排序。您可以执行以下操作(如果您的节点包含例如属性“名称”):

MATCH (u:User)
WITH u, rand() AS number
RETURN u
ORDER BY number
LIMIT 100

关于random - 如何使用 Cypher 在 Neo4j 中返回随机记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22179917/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com