使用 Gremlin 在 Amazon Neptune 中匹配多个标签
getting match on multiple labels in Amazon Neptune with Gremlin
Amazon Neptune 的 Gremlin 实现允许在顶点上使用多个标签(参见 https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-differences.html)
但是如何通过多个标签查询顶点?
g.V().hasLabel('label1').hasLabel('label2')
符合我的预期,但似乎并没有成功。
鉴于 Gremlin 语义,这:
g.V().hasLabel('label1').hasLabel('label2')
表示您正在执行 "and" 操作,因此顶点必须具有 "label1" 和 "label2"。如果您想要一个 "or" 操作,其中顶点可以有 "label1" 或 "label2" 那么您可能需要将其更改为:
g.V().or(hasLabel('label1'),hasLabel('label2'))
不确定这是否能解决您要查询的 Neptune 问题,但这正是 Gremlin 所期望的。
作为临时措施,您可以尝试 hasLabel('label1').fold().unfold().hasLabel('label2')
Amazon Neptune 的 Gremlin 实现允许在顶点上使用多个标签(参见 https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-differences.html)
但是如何通过多个标签查询顶点?
g.V().hasLabel('label1').hasLabel('label2')
符合我的预期,但似乎并没有成功。
鉴于 Gremlin 语义,这:
g.V().hasLabel('label1').hasLabel('label2')
表示您正在执行 "and" 操作,因此顶点必须具有 "label1" 和 "label2"。如果您想要一个 "or" 操作,其中顶点可以有 "label1" 或 "label2" 那么您可能需要将其更改为:
g.V().or(hasLabel('label1'),hasLabel('label2'))
不确定这是否能解决您要查询的 Neptune 问题,但这正是 Gremlin 所期望的。
作为临时措施,您可以尝试 hasLabel('label1').fold().unfold().hasLabel('label2')