3
votes

Amazon Neptune's implementation of Gremlin allows for multiple labels on vertices (see https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-differences.html)

But how to query for vertices by multiple labels?

g.V().hasLabel('label1').hasLabel('label2')

was what I expected, but does not seem to do the trick.

2

2 Answers

2
votes

Given Gremlin semantics, this:

g.V().hasLabel('label1').hasLabel('label2')

means that you're doing an "and" operation so the vertices must have "label1" and "label2". If you want an "or" operation where the vertices can have either "label1" or "label2" then you'd probably need to change that to:

g.V().or(hasLabel('label1'),hasLabel('label2'))

Not sure if that solves your problem with Neptune in what you want to query but that's what Gremlin expects.

2
votes

As an interim measure you could try doing hasLabel('label1').fold().unfold().hasLabel('label2')