gremlin - 使用 Gremlin 查询递归获取节点
问题描述
我想定义一个 Gremlin 查询,它递归地返回所有节点,直到没有更多可用节点:
Node: ProductionEvent
Node: Product
到目前为止我尝试过的是以下内容......但是,我不确定输出是否正确。另外,是否可以使用 tree() 函数将其打印出来?我可以使用times函数执行repeat函数来获取所有节点吗?
g.V().hasLabel('ProductionEvent').
repeat(__.outE('consumes').simplePath()).times(3).
emit().dedup()
我期待这样的输出
Product1: consumed <--- ProductionEvent1 --> produced :Product2: consumed <--- ProductionEvent2 --> produced :Product3
解决方案
我取得了令我满意的结果。查询是
g.V().hasLabel('ProductionEvent').has('orderID', 'XYZ')
.repeat(__.out('consumes').in_('produces').simplePath()).emit().times(5)
.dedup().limit(6).next()
据我了解,如果事先知道结果的数量,那么为了提高查询执行时间, limit()
and是必要的。times()
并且simplepath()
确保不会再次访问已经访问过的路径。
推荐阅读
- javascript - TypeError:无法在 App React 路由器上读取未定义的属性“参数”
- certificate - 将 signingCertificateV2 属性添加到 SignedCms
- postgresql - 如何在 Postgres 中正确索引和查询时间序列数据?
- javascript - 缺少从sails.js 文件上传返回的数据
- c++ - 我怎样才能找到素数反转数?
- amazon-web-services - AWS Redshift Distkey 和 Skew
- c++ - 将 QML 项目集成到 C++ 代码中的问题
- swift - 如何在 SearchController 中搜索 hashTag?
- dataframe - 火花数据框澄清选择
- javascript - 遍历对象数组并根据数组中出现的次数选择对象