组合 Gremlin 查询,通过某些属性或内部 ID 查找顶点和边

问题描述 投票:0回答:1

我想从 Java 运行 Gremlin 查询,通过节点和边的内部 ID 或一些其他属性(可以动态指定)来查找节点和边。它也可以是一个事务中的多个查询 - 无论哪种方法更快。我希望它适用于任何流行的 Gremlin 数据库(TinkerPop、JanusGraph、Orient、Neptune)。

我有一个查询几乎可以满足我的需要:

g.E().or(
  hasLabel('e1').has('value','abc'),
  hasLabel('e2').has('type','router')).
union(
  identity(),
  V().or(
    hasLabel('v1').has('name','john'),
    hasLabel('v2').id().is(within(123,456))))

此查询的唯一问题是通过边缘内部 ID 进行查询不起作用:

id().is('zzz')
hasId('zzz')
都不能在
or()
内部工作(但它可以在没有
or()
的情况下工作)。

gremlin
1个回答
0
投票

非常感谢您的建议。我能够使用“union”让它工作,它的作用类似于“or”:

g.E().union(
  hasId(within('abc','def')),
  has('e1','value','abc')).
union(
  identity(),
  V().union(
    hasId(within(123,456)),
    has('v1','name',within('john','kevin'))))

看起来 JanusGraph 尤其对我在问题中发布的查询有问题。

© www.soinside.com 2019 - 2024. All rights reserved.