【问题标题】:Gremlin reverse traversalGremlin 反向遍历
【发布时间】:2019-10-11 12:22:31
【问题描述】:

在 Gremlin graphdb 中,我有类似的东西:

root
   level1
      level2
        levelN

如果我知道“root”,我可以使用以下查询找到“levelN”:

g.v().has('name','root').repeat(out().simplePath()).until(has('name','levelN'))

但是我该如何走另一条路,鉴于我知道“levelN”,我如何找到“root”,这似乎是不可能的:

g.v().has('name','levelN').repeat(in().simplePath()).until(has('name','root'))

TIA

/索伦

【问题讨论】:

  • 您能否详细说明“似乎不可能”?遍历对我来说看起来不错,只有一个小问题,我认为这是一个错字(v() 应该是 V())。
  • 我正在使用 Azure CosmosDb 的 Graph 部分,如果我正在运行语句:g.V().has('name','Level3').repeat(in().simplePath( )).until(has('name','Root')) 在四节点图(层次结构)上,我收到错误:提交查询失败:g.V().has('name','Level3')。 repeat(in().simplePath()).until(has('name','Root')) ... 查询语法错误:脚本编译错误:缺少')'
  • 如果我将查询更改为:g.V().has('name','Level3').repeat(inE().otherV().simplePath()).until(has(' name','Root')) 它似乎工作

标签: gremlin graph-traversal


【解决方案1】:

根据您使用的客户端语言,in 是保留字,应写作__.in()in_()

查看 TinkerPop 文档中的顶点步骤以获取更多信息: http://tinkerpop.apache.org/docs/current/reference/#vertex-steps

【讨论】: