英文:
Gremlin: get a list of child nodes of a certain label n-levels deep
问题
我正在努力找出正确的命令。
从给定的节点开始,我想要获取特定标签的所有子节点,深度为n级。
例如:
假设我们从标签为'A'的节点开始。
A有类型为B或C的子节点(深度为1级)。
这些子节点B或C可以有类型为D或E的子节点(深度为2级)。
这些子节点可能再次有相同类型的子节点D或E,依此类推(深度为3+级)。
我想提取所有类型为E的节点,这些节点距离A为2级深度,即不考虑它们的子节点,这些子节点可能也是类型为E的(深度为3+级)。
感谢任何帮助!
我猜命令的起始部分将是 g.V('A')
。
编辑:请查看Kelvin的解决方案-对我来说很有效。
英文:
i'm struggling to figure out the correct command here.
Starting from a given node I would like to get all child nodes of a certain label n-levels deep
e.g.
imagine we start at a node with label 'A'.
A has child nodes of type B or C (1 level deep)
These child nodes B or C can have children of type D or E (2 levels deep)
These child nodes can again have further child nodes of the same type D or E and so on (3+ levels deep)
I would like to extract all nodes of type E that are 2 levels deep from A i.e., not look at their children that are 3+ levels deep that could also be of type E
Thanks for any help!
I guess the starting part of the command would be g.V('A')
Edit: See Kelvin's solution - that did the trick for me.
答案1
得分: 0
在其最简单的形式下,查找距离给定起始节点 2 跳的所有节点,这些节点具有特定标签,就像这样简单:
g.V('A').repeat(out()).times(2).hasLabel('E')
英文:
In its simplest form, finding all nodes, 2 hops away from a given start, that have a specific label is as simple as:
g.V('A').repeat(out()).times(2).hasLabel('E')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论