neo4j:有没有方法/如何选择随机节点? [英] neo4j: Is there a way/how to select random nodes?

查看:363
本文介绍了neo4j:有没有方法/如何选择随机节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索特定数量的随机节点.该图由3 000 000个节点组成,其中有些是源,有些是目标,有些都是.

I would like to retrieve a specific number of random nodes. The graph consists of 3 000 000 nodes where some of them are sources, some are target and some are both.

目标是检索随机源,并且由于我不知道如何选择随机,该程序会生成1到3 000 000个代表节点ID的k个随机数,然后丢弃所有不是源的随机选择的节点.由于此过程很耗时,我想知道是否可以通过密码查询直接选择随机源.

The aim is to retrieve random sources and as I don't know how to select random, the program generates k random numbers from 1 to 3 000 000 which represent node IDs and then discards all randomly selected nodes that are not sources. As this procedure is time-consuming, I wonder whether it is possible to directly select random sources with cypher query.

要选择所有来源,查询如下:

In case to select all sources, the query would be the following

START t=node(*) MATCH (a)-[:LEADS_TO]->(t) RETURN a

有人知道怎么可能直接用密码选择有限数量的随机节点吗?或者,如果不可能的话,建议任何解决方法?

Does anyone know how would it be possible to select the limited number of random nodes directly with a cypher or, if not possible, suggest any workaround?

推荐答案

您可以使用skip/limit限制查询,因此可以

You can limit your query with skip/limit so you could do

START t=node(*) 
MATCH (a)-[:LEADS_TO]->(t) 
RETURN a
SKIP {randomoffset} LIMIT {randomcount} 

否则,您还可以创建一组随机节点ID,并将它们作为参数传递给cypher语句.

Otherwise you can also create a set of random node-id's and pass them as parameter to the cypher statement.

这篇关于neo4j:有没有方法/如何选择随机节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆